Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT :: How to get form variable's value in javascript function ?

Status
Not open for further replies.

snr

Programmer
Oct 8, 2001
78
0
0
US
Hi ,
I want to use javascript for some simple client side validations, like if there are 2 textboexes, and if I write in second textbox, & first textbox is null , I want to give alert that first textbox value is null and the focus should be transfered to first textbox.
For this I need to know how to access value of form item in javascript, for which I used to write
document.form1.textbox1.value
in ASP.
I want equivalent for this statement.

Thanks ...

 
You can write a couple of client side functions and include them on your page that will give you any needed information about these dynamically created objects that you don't have much knowledge of at design time (at least not their names):

function sendMeAnObject(obj){
var objName = obj.name;
var objIndex = obj.returnIndex(obj.name);
}
//and another function to get the index:
function returnIndex(objName){
var i;
var index;
for(i=0;i<document.forms[0].length){
if (document.forms[0].elements.name == objName)
index = i;
}
return i;
}

Using these two functions should let you do whatever you need to do... no matter how deep you nest your controls... what they're named... whatever.

hth :)
paul
penny1.gif
penny1.gif
 
Using javascript on clientside how to retrieve the value in a text box ?
For example ,
<asp:textbox id =&quot;box1&quot; />
box1 has value &quot;ABC&quot;

I want to get this &quot;ABC&quot; using javascript on clientside function.

Thanks
 
May I first point out that this is really a javascript question for the javascript forum. That said I believe the following code will work.

document.form1.textbox1.value

I am not sure what you want however as you have the same code at the top of the page. [peace]
 
If you have:

<asp:textbox id =&quot;box1&quot; />

and in your codebehind, you say:

box1.attributes.add(&quot;onClick&quot;,&quot;sendMeAnObject(this);&quot;)

then, in that function, I listed up there, you can just ask:

obj.value

to get the value.
penny1.gif
penny1.gif
 
Thanks link9 ...........It worked !

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top