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

<INPUT> 1

Status
Not open for further replies.

scohan

Programmer
Dec 29, 2000
283
US
I'm using an <Input> of type image and calling an onlick funtion that validates data. Many <Input> tags call this validate function. Is there a way I can get the name of the <Input> tag that called the function? Thanks.
 
When you call the function - send the tag object to it:

<input type=&quot;image&quot; name=&quot;img_1&quot; onClick=&quot;validate(this)&quot;>

Then you just need to change the validate function to incorporate this information.

sample:

function validate(){
var name = (arguments[0])?arguments[0].name:null;

//...rest of validate functon
}

}


The reason I did this is so that the argument is optional, just in case you can't go back and change all the calls to it - or only sometimes you want to include the name.
Also it relies on the input having a (unique) name.

You may have to modify whatever is in the rest of the function to cope with the case where name =null, unless you are always going to send the object to the method.

Of course this entails modifying all the method calls, I don't think there is any Event.getSource() - not that I can find. ;-)
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top