maxim Posted June 6, 2006 Share Posted June 6, 2006 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 ? Link to comment https://forums.phpfreaks.com/topic/11295-set-values-for-a-element-solved/ Share on other sites More sharing options...
poirot Posted June 6, 2006 Share Posted June 6, 2006 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. Link to comment https://forums.phpfreaks.com/topic/11295-set-values-for-a-element-solved/#findComment-42290 Share on other sites More sharing options...
maxim Posted June 6, 2006 Author Share Posted June 6, 2006 i get a error [quote]Parse error: syntax error, unexpected T_VARIABLE in /var/www/html/php/news_adder.php on line 32[/quote]heres line 32[code]<input type="text" name="title" value="<?php$_POST['title_value'] ?>"/>[/code]also why do you have a "=" sign before the "$" sign when i do that i get a syntax error. Link to comment https://forums.phpfreaks.com/topic/11295-set-values-for-a-element-solved/#findComment-42294 Share on other sites More sharing options...
poirot Posted June 6, 2006 Share Posted June 6, 2006 Try [code]<input type="text" name="title" value="<?php echo $_POST['title_value'] ?>"/>[/code]or[code]<input type="text" name="title" value="<?= $_POST['title_value'] ?>"/>[/code] Link to comment https://forums.phpfreaks.com/topic/11295-set-values-for-a-element-solved/#findComment-42295 Share on other sites More sharing options...
maxim Posted June 6, 2006 Author Share Posted June 6, 2006 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. Link to comment https://forums.phpfreaks.com/topic/11295-set-values-for-a-element-solved/#findComment-42313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.