For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2006 > How to write to html textbox









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to write to html textbox
allan.madriaga@gmail.com

2006-03-20, 3:58 am

Hello,

Sorry for such a newbie question.
I want to retrieve information from a database and display the results
into relating textboxes.
What java function do I use to access and write to an already existing
textbox on an html page?

Thanks in advance.
Allan

Nandu

2006-03-20, 3:58 am

i think

to read textbox.getText()
and to write textbox.setText("STring or Message")

hope this is correct

allan.madriaga@gmail.com

2006-03-20, 9:57 pm

Thanks for the reply Nandu. You are correct. getText() is to read the
textbox value but I guess my problem is accessing it. What I am doing
is I am writing a. aspx page and using j# (basically java) for the
server-side scripting. Between the <script> tags at the top of the html
page, I am writing some functions. One of these functions will write to
the textbox. My problem is that I cannot access the textbox within the
<script> tags. The textbox is not within its scope.

Any Ideas?

Thanks,
Allan

Oliver Wong

2006-03-20, 9:57 pm


<allan.madriaga@gmail.com> wrote in message
news:1142868153.286717.217120@u72g2000cwu.googlegroups.com...
> Thanks for the reply Nandu. You are correct. getText() is to read the
> textbox value but I guess my problem is accessing it. What I am doing
> is I am writing a. aspx page and using j# (basically java) for the
> server-side scripting. Between the <script> tags at the top of the html
> page, I am writing some functions. One of these functions will write to
> the textbox. My problem is that I cannot access the textbox within the
> <script> tags. The textbox is not within its scope.
>
> Any Ideas?


.NET has its own (in my opinion weird) order-of-execution rules. From
what I understand, any action the user executes on ASPX controls will cause
a resubmit to occur to the server for processing. Check that you're using an
ASPX textbox, and not an HTML one.

Other than that, try a .NET newsgroup, instead of a Java one.

- Oliver

Hal Rosser

2006-03-20, 9:57 pm

> Sorry for such a newbie question.
> I want to retrieve information from a database and display the results
> into relating textboxes.
> What java function do I use to access and write to an already existing
> textbox on an html page?


When java is creating the Web page to display the data, just add the 'value'
attribute to the html tag.
<input type="text" name="CompanyName" value="ABC corporation" />
the words "ABC corporation would appear in the text box.
I'm not sure you asked the question like you meant to.


geeker87@gmail.com

2006-03-21, 7:57 am

Okay, I'm not familiar with aspx or anything, but I think I know what
your trying to do.

You can't access the textbox because aspx won't allow you to, or it has
already been rendered by the browser? (i.e. that part of the html
output has already been sent..).

Trick: Use javascript.

<input type="text" name="foo" id="bar"/>

inyour script, output a couple of lines of javascript to the page:
<script type="javascript">document.getElementById('bar').setValue("ABC
Corporation");</script>

Thats just off the top of my head and I don't use JS much so it might
not be 100% correct.

-- Matt

Hal Rosser

2006-03-21, 10:07 pm


<ger87@gmail.com> wrote in message
news:1142939782.847269.319370@i40g2000cwc.googlegroups.com...
> Okay, I'm not familiar with aspx or anything, but I think I know what
> your trying to do.
>
> You can't access the textbox because aspx won't allow you to, or it has
> already been rendered by the browser? (i.e. that part of the html
> output has already been sent..).
>
> Trick: Use javascript.
>
> <input type="text" name="foo" id="bar"/>
>
> inyour script, output a couple of lines of javascript to the page:
> <script type="javascript">document.getElementById('bar').setValue("ABC
> Corporation");</script>
>
> Thats just off the top of my head and I don't use JS much so it might
> not be 100% correct.
>


I assumed the user was using java (perhaps jsp) to access the database and
to display the data in text boxes.
Since the text boxes are created at the time of creating the html page, I
assumed the OP was asking the wrong question, or made wrong assumptions.
Java does not access the page after it has been rendered - but JAVASCRIPT
can. But Javascript can not access the database.
The best solutions involves html, css, java, servlets, and javascript.


Oliver Wong

2006-03-22, 7:06 pm

"Hal Rosser" <hmrosser@bellsouth.net> wrote in message
news:FI_Tf.758$qe.410@bignews1.bellsouth.net...
>
> Java does not access the page after it has been rendered - but JAVASCRIPT
> can. But Javascript can not access the database.


JavaScript can ask the browser to make an HTTP request. In responce to
this request, the HTTP server can query the DB, then formulate an XML
document representing the results of the query, and return that to
JavaScript.

That's the basis on which AJAX is built.

- Oliver

Hal Rosser

2006-03-22, 10:02 pm


"Oliver Wong" <owong@castortech.com> wrote in message
news:HYfUf.144$B_1.108@edtnps89...
> "Hal Rosser" <hmrosser@bellsouth.net> wrote in message
> news:FI_Tf.758$qe.410@bignews1.bellsouth.net...
JAVASCRIPT[color=darkred]
>
> JavaScript can ask the browser to make an HTTP request. In responce to
> this request, the HTTP server can query the DB, then formulate an XML
> document representing the results of the query, and return that to
> JavaScript.
>
> That's the basis on which AJAX is built.
>
> - Oliver
>


Ah yes - AJAX
But keep in mind that client-side javascript still does not access the
database
- the request you speak of is sent to the server,
and then javascript can process the response the server returns.
Java still does not access the text box.
(We agree.)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com