vinpkl Posted November 19, 2009 Share Posted November 19, 2009 hi all a strange thing is happening i have two fields "new_cutout" and "new_price". they both are defined as float fields in mysql. i m updating their values and also validating them with javascript. If I enter "500.00" in new_cutout field and "0.00" in new_price field and press submit button then both the values of new_cutout field and new_price field changes to "0.00" automatically. not able to know why is the value of new_cutout changing to "0.00" automaticaly. Is the problem of javascript or float. <script language="javascript"> function validate() { if(document.form1.new_cutout.value='0.00') { alert("Enter new cutout price"); return false; } if(document.form1.new_price.value='0.00') { alert("Enter new price"); return false; } } </script> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return validate();"> <input type="text" name="new_cutout" id="new_cutout" /> <input name="new_price" type="text" id="new_price" /> <input type="submit" name="submit" id="submit" value="Modify Product Price" /></td> </form> <?php $msg=""; if(isset($_REQUEST['submit'])) { $new_cutout=$_REQUEST['new_cutout']; $new_price=$_REQUEST['new_price']; $qry="update product_table set cutout_price=$new_cutout, price=$new_price where product_id=$id"; if(mysql_query($qry)) { $msg="Product Price updated successfully"; } else $msg="Error updating product Price"; } ?> vineet Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 19, 2009 Share Posted November 19, 2009 because when u refreshed the page it cleared the inputted text? i dont really undestand what ur questionis are they really 0.00 or is it just 0? i dont know why urusing request. wouldnt u normally use $_POST? Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 19, 2009 Author Share Posted November 19, 2009 hi emopoops on clicking the submit button the validation works and shows the alert "enter cutout price". the page didnt refreshed. the value changes to "0.00" but i entered 500.00 in that field. vineet because when u refreshed the page it cleared the inputted text? i dont really undestand what ur questionis are they really 0.00 or is it just 0? i dont know why urusing request. wouldnt u normally use $_POST? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 19, 2009 Share Posted November 19, 2009 This is more a javascript problem, but if(document.form1.new_cutout.value='0.00') should be if(document.form1.new_cutout.value=='0.00') you want to use the comparison operator(==) not the assignment operator(=) Whats happening is you are assigning that value of your text box 0.00, and the assignment operator returns true when your assignment assigns to something that is not NULL or false. Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 19, 2009 Share Posted November 19, 2009 oh i see. yeah does the == work? Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 19, 2009 Author Share Posted November 19, 2009 Thanks mikesta it worked. vineet This is more a javascript problem, but if(document.form1.new_cutout.value='0.00') should be if(document.form1.new_cutout.value=='0.00') you want to use the comparison operator(==) not the assignment operator(=) Whats happening is you are assigning that value of your text box 0.00, and the assignment operator returns true when your assignment assigns to something that is not NULL or false. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.