Radio button problem

C

chumley

i'm trying to add 70 dollars to a price total if a user selects the
second radio button in a group named inks1, which has a radio button
value of 2, but in my orderTotal function, i cannot get the selection
to add 70 to the price total in the following:

section of javascript orderTotal function:

if(isNaN(qty.value) || (qty.value <= 0))
{
qty.value = "";
stHold.value = "";
}


// else the field is a valid number, so calculate the
// total order cost and put that value in the
// hidden subtotal field
/// radiobutton check
if (document.oform.inks1.value = 2){
stHold.value = (Math.round(qty.value * (price.value + 70) * 100))/
100;}
else
{
stHold.value = (Math.round(qty.value * price.value * 100))/100;
}

html:
<input type = "radio" name="inks1" id="inks1" value="2"
onclick="orderTotal()">


wondering if i have to create a separate function for the radio button

??
chumley
 
S

Scott Sauyet

i'm trying to add 70 dollars to a price total if a user selects the
second radio button in a group named inks1, which has a radio button
value of 2, but in my orderTotal function, i cannot get the selection
to add 70 to the price total in the following:
[ ... ]
if (document.oform.inks1.value = 2){

Radio buttons are a little different from other controls. I'm
assuming that you have more than one, correct? If not, a checkbox is
a much better control. But to get the value, you will need to loop
through the elements and get the value of the one that is checked.
Alternatively, if you really only need to check one, you can do

if (document.getElementById("inks1").checked) { /* ... */ }

But if you only need to check one of them, perhaps a radio button is
not the best control.

Good luck,

-- Scott
 
R

Richard Cornford

On Jan 20, 4:32 pm, chumley wrote:
html:
<input type = "radio" name="inks1" id="inks1" value="2"
onclick="orderTotal()">
<snip>

If you only have one radio button why isn't it a checkbox (as radio
buttons are designed to work in groups), and if there are others why
are you claiming that this is the html?

Richard.
 
K

Kabindra

1. using parseInt(qty.value) <= 0 can be useful or ....
2.) use
if (document.oform.inks1.checked == true)
 
T

Thomas 'PointedEars' Lahn

Kabindra said:
1. using parseInt(qty.value) <= 0 can be useful or ....

No, read the FAQ. Always provide the base if you use parseInt().
2.) use
if (document.oform.inks1.checked == true)

No, read the FAQ. Loose comparison with `true' is superfluous. And use
standards-compliant and backwards-compatible referencing.

if (document.forms["oform"].elements["inks1"].checked)

Of course, either is only backwards-compatible if their is only *one*
control with the *name* "inks1" in the *one* form with the *name* "oform".
(`document.forms["oform"]' can be replaced by an argument name if the form
object reference is passed to the validator method.)
[Top post]

Learn to quote. That's also in the FAQ (Notes).

<http://jibbering.com/faq/#posting>


PointedEars
 
E

Evertjan.

Kabindra wrote on 21 jan 2010 in comp.lang.javascript:
2.) use
if (document.oform.inks1.checked == true)

Which is the same as:

if (document.oform.inks1.checked)

Why this testing

if (true == true)

and

if (false == true)

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top