From: chumley on
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
From: Scott Sauyet on
On Jan 20, 11:32 am, chumley <blueberry...(a)yahoo.com> wrote:
> 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
From: Richard Cornford on
On Jan 20, 4:32 pm, chumley wrote:
<snip>
> 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.
From: Kabindra on
1. using parseInt(qty.value) <= 0 can be useful or ....
2.) use
if (document.oform.inks1.checked == true)



On Jan 20, 9:32 pm, chumley <blueberry...(a)yahoo.com> wrote:
> 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

From: Thomas 'PointedEars' Lahn on
Kabindra wrote:

> 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
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)