Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/182113-solved-form-behaving-strange/
Share on other sites

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?

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.