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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing both formid and texbox id to a function

Status
Not open for further replies.

guestAsh

Technical User
Feb 27, 2004
65
GB
Hiya - i need to change the value of a textbox when a fuction has been called.

There are several forms on a page,

so to call a functiom i am using a onclick event somthing like this :
Code:
 onclick="dropdata(frmname,textname)"

what Syntax do i need to use?

if i knew the form ID then i would use this:

Code:
document.form1.getElementById(textname).value = "0"

but i don't so want to use the formname (frmname) that was passed through to the function....

any help?

Thanks

Ash
 
Ok worked it out:

Code:
document.getElementById(textname).value = "0"

i was just being thick!
 
That only works if the ID and name of the element are the same which they don;t have to be. . Supposing you have something like:

<input type=text name="mytextbox" id="somethingelse">

Then your function will throw out an error.

If you want to use the "name" of an elment as opposed tot he ID you'll need to do it through getElementsByName()

var mytextbox=document.getElementsByName('nameofelement')[red][0][/red];

The zero in brackets will return the first element if finds with that name.

However if you have more then one element with the same name, then it will get difficult.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top