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

Transfering values from HTML Form to Javascript

Status
Not open for further replies.

Largins421

Programmer
Sep 10, 2007
6
US
Hello,

I have been programming for a long time (since 1968), web programming is quite new to me, and I am baffled by an issue I am having which involves an HTML Form and a Java script handler. The form is for a shopping cart, and was working fine until I needed to add some radio buttons to specify the desired finish for a particular product. The code for the working form (different product) follows:

<FORM NAME=order ACTION="managecart.html" onSubmit="AddToCart(this);">
Quantity: <input type=text size=2 maxlength=3 name=QUANTITY
onChange='this.value=CKquantity(this.value)' value="1"><BR><BR>
<input type="image" src="./images/buynow.gif"
border=0 value="Add to Cart" align=top>
<input type=hidden name=PRICE value="2.95">
<input type=hidden name=NAME value="M802 Baseball Glitter Sport Medal">
<input type=hidden name=ID_NUM value="M802">
<input type=hidden name=SHIPPING value=".795">
</FORM>

Please note the value ID_NUM, this is what I want the radio button to populate. The non-working code follows:

<FORM NAME=order ACTION="managecart.html" onSubmit="AddToCart(this);">
Quantity: <input type=text size=2 maxlength=3 name=QUANTITY
onChange='this.value=CKquantity(this.value)' value="1"><BR><BR>

Finish:
<input type="radio" name=ID_NUM value="M702-G" checked> Gold
<input type="radio" name=ID_NUM value="M702-S"> Silver
<input type="radio" name=ID_NUM value="M702-B"> Bronze<BR>
<input type=hidden name=ID_NUM value="Test">
<input type="image" src="./images/buynow.gif" border=0 value="Add to Cart" align=top>
<input type=hidden name=PRICE value="1.75">
<input type=hidden name=NAME
value="M702 Baseball Star Series Sport Medal">
<input type=hidden name=SHIPPING value=".795">
</FORM>

With the second form, when i try to access ID_NUM (from the shopping cart script), the value is undefined.

I;m sure that this is a simple issue (if you know the answer), but darned if I can find it.

I also tried re-naming the radio buttons to Finish, and inserting a javascript snippet in the html code after the radio button which follows:

<script type="text/javascript">
order.ID_NUM.value = order.Finish.value;
</script>

That did not work either.

Any help would be greatly appreciated.

Larry
 
Sorry,

the
<input type=hidden name=ID_NUM value="Test">
was a sanity insert (to make sure ID_NUM) worked, and is not part if the non-working code.
 
This answer depends on your shopping cart script, but it's probably in the right area...

You cannot access a single radio button's value when there are multiple buttons with the same name. When this is the case, you effectively have a control array, so you need to loop over all radio buttons with that name finding out which ha its "checked" attribute set to "true". Then you can query the "value" attribute of the checked one to find which value was sent.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,

This does make sense, now all I need to do is figure out how to access the array. Shouldn't be too difficult. Thanks for the advice.

Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top