Page 1 of 1

Can't Override the Default Value of the Textbox

Posted: Tue May 18, 2010 4:37 pm
by makamo66
I have an html textbox that was written like this:

Code: Select all

echo "<b>Quantity:</b> <input type=\"text\" name=\"qtyBox\" value=\"1\" size=\"1\" />";
When the form is submitted I collect the value of the textbox like this:

Code: Select all

	$_SESSION['qtyBox'] = $_POST['qtyBox'];
	$qtyBox = $_SESSION['qtyBox'];
	echo $qtyBox;
The problem is that no matter what I type into the text box, the value is echoed out as 1. If I leave the value blank and type a number into the box, I get a blank too.

Re: Can't Override the Default Value of the Textbox

Posted: Tue May 18, 2010 6:56 pm
by JakeJ
When your echo is surrounded by double quotes, replace all of the double quotes except the first and the last with single quotes as follows.

Code: Select all

echo "<b>Quantity:</b> <input type='text' name='qtyBox' value='1' size='1' />";

Re: Can't Override the Default Value of the Textbox

Posted: Tue May 18, 2010 7:28 pm
by flying_circus
JakeJ wrote:When your echo is surrounded by double quotes, replace all of the double quotes except the first and the last with single quotes as follows.

Code: Select all

echo "<b>Quantity:</b> <input type='text' name='qtyBox' value='1' size='1' />";
Why? Escaping the double quotes as he is doing will work fine and is acceptable when encapsulated within double quotes. I believe the HTML spec says to encapsulate element attributes in double quotes as oposed to single quotes.

makamo66:
mocking up your code, the following will put out whatever I have typed in the input box.

Code: Select all

echo $_POST['qtyBox']; 
Are you sure your form is set to method post?
Are you starting your session at the top of the script?
Are you only executing this block of code when the request method is a post?

What happens if you just echo out the post value, as I've done above?