calvin12
calvin12

Reputation: 211

NaN error in jquery. Have tried ParseInt, still not working

whats wrong with my code here??

var value = $('#qty').val() * $('#rate').val();
var tax =  value * $('#tax').val() / 100;
$('#valueshow').text(tax);
$('#value').val(value);

the html part is

<input type='text' name='qty"' size = '5'>
<input type='text' name='rate' size = '5'> 
<input type='text' name='tax' size = '5'> 
<input name='value' id='value'> 
<span id='valueshow'></span>

its giving NaN error..please help

Upvotes: 0

Views: 1586

Answers (2)

GautamD31
GautamD31

Reputation: 28763

Give your html code as

<input type='text' name='qty' id='qty' size = '5'>
<input type='text' name='rate' id='rate' size = '5'> 
<input type='text' name='tax' id='tax' size = '5'> 
<input name='value' id='value'> 
<span id='valueshow'></span>

whenever you had used id's for the hyml elements then only you can use "#" as ('#qty').val() hope you can use this

Upvotes: 0

Hkachhia
Hkachhia

Reputation: 4539

You have error in jquery code because jquery # use for id. In your code you does not apply Id in html input type so apply id and try it like

 $('#qty').val() 

<input type='text' name='qty' id='qty' size = '5'>

Upvotes: 4

Related Questions