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

form confusion: how to grab value when onclick

Status
Not open for further replies.

Candyb

Technical User
Oct 2, 2001
12
CA
Hi,

I have a submit button that goes to my javascript function.
I have a while i < 5 where i = 0 let var1 = i;
The submit button has a name=submit value=submit and an id attribute that gathers it values form the var1...so
id=var1. so in the end i have 6 submit buttons all with different id values. I am able to do this through my xml/xsl files. which is beside the point. :) but anyways, with each submit button i also have an onClick that goes to the javascript function.

What I would like to know is how do I only obtain the value of the id that the user has clicked? ie, user clicked second submit button and so my id = 1

what is the syntax for grabbing this id and showing it my my alert box?alert(id)...shows 1

Thanks,
Candy

PS. if this is a bad way of doing this, I'm up for some better suggestions:)
 
How about passing the id to the onClick function? You can generate the code for that the same way you generate the id numbers. For example:
Code:
<input type=&quot;submit&quot; name=&quot;s1&quot; id=&quot;1&quot; value onClick=&quot;myfunc('1')&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
How about passing the id to the onClick function? You can generate the code for that the same way you generate the id numbers. For example:
Code:
<input type=&quot;submit&quot; name=&quot;s1&quot; id=&quot;1&quot; value=&quot;sub1&quot; onClick=&quot;myfunc('1')&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Oops, I realized as I hit submit that I hadn't finished the value attribute, but didn't hit stop quickly enough.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I feel silly but I realized i just had to pass that value in to the function.

But I get errors when I create this string..how can I avoid it?

var strUrl = &quot;tipsheetvb.asp?display=&quot; + display;
var strUrl2 = &quot;&tip_id=&quot; + strID;
var strALL = strUrl + strUrl2;

It says i need a ; at the end of tip_id...I really need those special characters.

Thanks,
Candy
 
I'm not sure what's wrong there. I looks OK to me. Maybe someone else can spot something. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top