HTML: Populating textarea from query<

liunx

Guest
Hi I'm creating an update page: the user enters a record id and submits it, and the record for that id appears, each field in its own textbox,textarea and checkbox.
The problem is that the value for the textarea ie the text isn't being inserted and doesn't appear on the page. Also the checkbox doesnt change whether the value is 1 or 0.

textarea
<td colspan=\"3\" rowspan=\"3\"><textarea name= \"Comments\" value= '$row[21]' cols=\"40\" rows=\"6\"></textarea>
</td>

checkbox
<td><input type=\"checkbox\" name=\"FDD\" value=\"$row[7]\"</td>

all this HTML is within a PHP script hence the \ escaping the ". I was unsure whether to post here or on the PHP forum.

I have attached a larger amount of code if it helps

BobNZfor one textareas don't have value attributes.

textarea
<td colspan=\"3\" rowspan=\"3\"><textarea name= \"Comments\" cols=\"40\" rows=\"6\">$row[21]</textarea>
</td>

for a checkbox you need to put checked in it, and keep the value to a value you want.

checkbox
<td><input type=\"checkbox\" name=\"FDD\" value=\"$row[7]\" checked></td>Thanks Scoutt that sorted the Textarea but the check boxes need to show their state from the last time they where updated. Putting checked in makes them checked (lol).
So even when the variable contains a "0" it makes no difference the checkbox remains checked. Am I being clear here? I am new to HTML/PHP so......
thanks for your help though.

BobNZthe value has no control over if it is checked or not. if you want a checked checkbox then you have to check what the user posted.

example on the next page after they hit submit
lets say the value we have in the checkbox is 1

<td><input type="checkbox" name="FDD" value="1" ></td>

the value can be anyhing you want, I just use 1 to be simple.


<?php
if ($_POST['FDD']) == 1){
$checkvalue = "checked";
} else {\
$checkvalue = "";
}

<td><input type=\"checkbox\" name=\"FDD\" value=\"$row[7]\" $checkvalue></td>

does that make since? if the value is 1 then we want to make it checked, if the value is anyhting but 1 then we don't want it checked.Hey thats great thanks a lot Scoutt.

BobNZI thought you had it. However some confusion, I'm trying to display a existing record so the $row[7]is the result of a query not a $_POST I tried a variation on your code but have not been able to get the checkbox to show the state of 'FDD' // $row[7] as returned by the query.

print_r($row[7]); returns 1
print_r($checkvalue); returns CHECKED

Any ideas?

BobNZ

$ROWquery= "select * from tblWorkstation where WSID = '".$_POST['WSID']."'";
$result = mysql_query($ROWquery,$connection);
$row=mysql_fetch_row($result);

if (($row[7])== 1)
{
$checkvalue = "CHECKED";
} else {
$checkvalue = "";
}
print "<table width=\"80%\" bordercolor=\"#FFFFFF\" bgcolor=\"#3399CC\" >";
print " <tr>
<td><input type=\"checkbox\" name=\"FDD\" \"$checkvalue\" ></td>

</tr>";
print "</table>";you have it correct, but you forgot the value in this line

<input type=\"checkbox\" name=\"FDD\" \"$checkvalue\" >

also the checked doesn't go into quotes.

<input type=\"checkbox\" name=\"FDD\" value=\"$row[7]\" $checkvalue >

if it isn't checked try selected insteadThanks Scoutt removing the \" from $checkvalue solved it.
I dont need to have the value=$row[7] do I? as I check this value to set $checked

BobNZyou should have a value. unless you don't need to send this to anything, not even a script. if you plan on this being able to update the database then yes you have to have one.OK then, thanks a lot for the help.

BobNZ
 
Back
Top