Jump to content


Photo

set values for a <form> element #solved


  • Please log in to reply
4 replies to this topic

#1 maxim

maxim
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 06 June 2006 - 03:38 AM

Hi,

i have a text box with a default value of null.

There is a particular button i have that once you press it, it populates a select menu with data from a database.
when a user selects a particular item in the select menu i wish to set the textbox value to "some string".

i can use the $_POST array superglobal to to retrevie the information i need, but how do i set it ?

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 03:46 AM

For text, textarea and password fields you can use value="<?=$_POST['data']?>

For radio, checkbox, select fields you would have to use something to add 'checked="checked"', 'selected="selected"', and so on. It's harder.
~ D Kuang

#3 maxim

maxim
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 06 June 2006 - 04:05 AM

i get a error

Parse error: syntax error, unexpected T_VARIABLE in /var/www/html/php/news_adder.php on line 32


heres line 32

<input type="text" name="title" value="<?php$_POST['title_value'] ?>"/>

also why do you have a "=" sign before the "$" sign when i do that i get a syntax error.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 04:08 AM

Try

<input type="text" name="title" value="<?php echo $_POST['title_value'] ?>"/>

or

<input type="text" name="title" value="<?= $_POST['title_value'] ?>"/>

~ D Kuang

#5 maxim

maxim
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 06 June 2006 - 05:33 AM

putting the "echo" statment made it work - thanks alot for the quick reply and solution!

can believe i didnt think of it.

Just curious tho is that the only way to do it? what is the recomended way? all the books i have simply retrive values from forms. the only ones where they set values are for select menus.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users