How to pass the contents of a text box as a string

A

AAaron123

<input id="txtStart" type="text" name="txtStart" value="620 Rugter Street ,
Utica, NY,13501" style="width:150px;"/>

<input id="txtEnd" type="text" name="txtEnd" value="168 Genesee Street,
Utica, NY,13502" style="width:300px;"/>

<input id="btnFind" type="button" name="btnGetRoute" value="Find"
onclick="GetRoute(txtStart.value,'168 Genesee Street, Utica, NY,13502');"
style="width:200px;"/>

The question relates to the button. If I use for both argument a string
like I used for the second argument it works OK.



But when I try to use the values in the text boxes, like I show for the
first argument, I can't get it to work.

The routine in the head starts with

function GetRoute(start, end) {

alert(start);

alert displays "undefined"



I don't want to send a reference to the textbox.

I want to send the contents as a string.



Thanks
 
N

Nathan Sokalski

Use something like the following:

onclick="GetRoute(document.getElementById('txtStart').value,'168 Genesee
Street, Utica, NY,13502');"

Whenever you reference an element using JavaScript, you should use the
document.getElementById() method. In some cases, the id of an element will
be automatically generated by ASP.NET. In this case, you will need to
dynamically generate the JavaScript using the ClientID property of the
Control class (because Control is inherited by the WebControl class, all the
WebControls such as TextBox have this property available). Hopefully all
this helps! Good Luck!
 
A

AAaron123

Thanks, that worked.


Nathan Sokalski said:
Use something like the following:

onclick="GetRoute(document.getElementById('txtStart').value,'168 Genesee
Street, Utica, NY,13502');"

Whenever you reference an element using JavaScript, you should use the
document.getElementById() method. In some cases, the id of an element will
be automatically generated by ASP.NET. In this case, you will need to
dynamically generate the JavaScript using the ClientID property of the
Control class (because Control is inherited by the WebControl class, all
the WebControls such as TextBox have this property available). Hopefully
all this helps! Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top