Simple javascript not working

Hello,

I have made a simple javascript but its not working. Can anyone help ??

        if (document.f1.baseprice.value <> "0") { var baseprice = document.f1.baseprice.value; } else { var baseprice = 0; }
        if (document.f1.ringmetal.value <> "0") { var metal = document.f1.ringmetal.value.split("-"); } else { var metal = 0; }
        if (document.f1.ringcolour.value <> "0") { var colour = document.f1.ringcolour.value.split("-"); } else { var colour = 0; }
        if (document.f1.ringclarity.value <> "0") { var clarity = document.f1.ringclarity.value.split("-"); } else { var clarity = 0; }
        if (document.f1.ringsize.value <> "0") { var ringsize = document.f1.ringsize.value.split("-"); } else { var ringsize = 0; }

        var total = Number(baseprice);

        if (metal <> 0) { total = Number(total) + Number(metal[0]);
        if (colour <> 0) { total = Number(total) + Number(colour[0]);
        if (clarity <> 0) { total = Number(total) + Number(clarity[0]);
        if (ringsize <> 0) { total = Number(total) + Number(ringsize[0]);

Can you please tell me what I am doing wrong in this ?

Thanks.

To be able to help you, we need more information than that. For the most effective help, you should provide 4 pieces of information:

  1. Script purpose
  2. Expected result
  3. Actual result
  4. Entire script

Many people post very little about their script, and then very little of their script and there’s no way to tell what’s supposed to happen, which line your error is on, what variables are set when we get to this part of the script or what happens to the data we set here afterwards. Having little or no information makes it very difficult to render any real help.

<> is not a JavaScript operator.

Oh. Yeah, that’d do it too. I should have caught that. Well played, L.A.

To clarify, the not equal to operator in javascript is != or !==

Okay. So when you split your values, you’re basically making an array of (in that case):
0: 10
1: Some Option

After each .split(‘-’), place [0] so that it will reference the first element of that array. It will look like this:
if (document.f1.ringmetal.value !== “0”) { var metal = document.f1.ringmetal.value.split(“-”)[0]; } else { var metal = 0; }

Alright, may I see what your dropdown values look like?

Hello,

All 4 dropdown have values like:

<option value=“10-Some Option”>Some Option</option>

Thanks.

Hello,

Script purpose: To get values of 4 dropdown’s and 1 text box and add them all up to make a total value.

Expected result: Total value of all 5 fields.

Actual Result: Not calulating

Entier Script: That is the entier script.

Thanks.