August 17, 201016 yr Hi guys, I'm not the best at JavaScript, can somebody be so kind and review the following and see if there is anything they notice that could be causing this form not to work properly. Issue: After submit, form displays correct calculations for a split second and then resets to be blank. Script function CalculateSum(xtext, ztext, form) { var x = parseFloat(xtext); var z = parseFloat(ztext); form.Yield.value = (x / z); } function ClearForm(form) { form.input_x.value = ""; form.input_z.value = ""; form.Yield.value = ""; } function doClear(theText) { if (theText.value == theText.defaultValue) { theText.value = ""; } } Form <form name="Calculator" method="post" runat="server" onSubmit="return checkform()"> £ <input name="input_x" type="text" /> £ <input name="input_z" type="text" /> <input name="Yield" readonly="readonly" type="text" /> % <input name="ClearButton2" type="button" onclick="ClearForm(this.form)" value="clear" /> <input type="submit" name="AddButton" onClick="CalculateSum(this.form.input_x.value, this.form.input_z.value, this.form)" value="submit" /> </form> This should be so straight forward, I'm sure I'm missing something silly. Thanks in advance!
August 17, 201016 yr Got a live example? I've not done this for a while, but isn't a page refresh default behaviour? Which would require a return false; to counteract it.
August 17, 201016 yr Author Got a live example? I've not done this for a while, but isn't a page refresh default behaviour? Which would require a return false; to counteract it. Homer Simpson moment i think it was here! return false did the trick. I don't know why but an old version of the same calculator worked without it for some reason so it slipped my mind to include it in this one! Thank you so much! +1
August 17, 201016 yr Sometimes it just takes a fresh set o' eyes Thanks for the +1, people always forget to do that to me
August 17, 201016 yr Author Sometimes it just takes a fresh set o' eyes Thanks for the +1, people always forget to do that to me Yes indeed! I'm a web developer on a creative team of 4 and the other guys know nothing of JavaScript at all so they didn't even bother taking a look, but, once again this place gave me my answer within an hour! I love it!
Create an account or sign in to comment