1

when i select only the first dropdown, the result in #output showing NaN?
http://jsfiddle.net/boyee007/TJcP4/
i want, if the first dropdown is selected is showing 30 then if both selected will calculate the both value

<select id="t_dermal_name">
     <option value="1" rel="30">Between Eyebrows</option>
     <option value="7" rel="30">Individual Line Softening</option>
     <option value="2" rel="30">Lip Contouring</option>
</select>
<select id="t_wrinkle_name">
     <option value="1" rel="30">Between Eyebrows</option>
     <option value="7" rel="30">Individual Line Softening</option>
     <option value="2" rel="30">Lip Contouring</option>
</select>

var output = 0;
var output1 = 0;
if($("#t_dermal_name").val() != 0){
    enter code here`output = $("#t_dermal_name").find('option:selected').attr('rel');
 }
 if($("#t_wrinkle_name").val() != 0){
     output1 = $("#t_wrinkle_name").find('option:selected').attr('rel');
 }
 $("#output").html(parseInt(output) + parseInt(output1)); 
1
  • +1 to the question for using jsfiddle like a pro Commented Jan 7, 2011 at 13:37

4 Answers 4

2

I took the liberty to update your example.

Is this the functionality you were looking for?

Sign up to request clarification or add additional context in comments.

Comments

0

You have t_dermal_name id repeated twice. You probably meant second one to be t_wrinkle_name.

And that's not counting enter code hereoutput = ...` part :)

1 Comment

sorry my bad.. jsut made a change :)
0

Because output1 isn't set, so parseInt(output1) == NaN (Not A Number). When you add this to any other number (i.e. the value from parseInt(output)) the total remains NaN.

You should check that output1 is set before attempting to parse it and add it.

Comments

0

Try this

var output=0;
var output2=0;

$("#t_dermal_name").change(function(){
     output = $("this").attr('rel');
});

$("#t_wrinkle_name").change(function(){
     output2 = $("this").attr('rel');
});


$("#output").html(parseInt(output) + parseInt(output1)); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.