how to fix value in form
here i fills three value in name field ,# of cake field,#of peanut field and then i want a form with all the values in name,subtotal and total field to be field but Nan appears in total,subtotal field and that is just for a instance.NaN appears only for short duration and immediate form gets refresh and blank form is appared.
Name<input type="text" id="name"><br>
# of cake<input type="text" id="cake"><br>
# of peanut<input type="text" id="peanut"><br>
Subtotal<input type="text" id="subtotal"><br>
Tax<input type="text" id="tax"><br>
Total<input type="text" id="total"><br>
<input type="submit" onclick="totalfu();" value="order"><br>
I don't see any jquery in this... Anyway, the reason you see 'NaN' for a short duration and then the page refreshes is because your <form> has no action set. Thus the form submits itself to the same page (so the page refreshes, clearing the form). If you want the data to go somewhere you should have an action set (and a page that can read/process the data once received). If you just want the form to do a calculation, well then you shouldn't really be using a form (as these are essentially for submitting data).
Now as for why 'NaN' appears. It's because you store your values in variables named 'cake1' and 'peanut1' but then in your calculation you are using 'cake' and 'peanut', which do not have values, thus they return 'NaN' (not a number) when you try to preform mathematical operations on them. So you just need to update your variable names to the correct ones (either use 'cake1' and 'peanut1' for both, or 'cake' and 'peanut' for both).
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
I agree with the rest of your comments, but disagree with this one point. The form is being used to take input as well as display the result of a calculation, so I think it is perfectly legitimate.
Originally Posted by Sup3rkirby
- It is more secure.
- Presumably you want to do something with the order if a "buy" button is pressed.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread