jib Posted June 20, 2008 Share Posted June 20, 2008 So I hit another brick wall, I googled, didn't find the answer so here goes, I am using variables to fill form fields. The text boxes/ text areas were simple. But what do you do for radio buttons and drop down menu's? I want to set the the default value for these fields to value of the variable. Basically it's just an update entry form so if they clicked a radio button when they submitted that button will be check and if they picked a certain drop box value it will have that one selected. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/ Share on other sites More sharing options...
trq Posted June 20, 2008 Share Posted June 20, 2008 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569904 Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 can you demonstrate a bit more? Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569906 Share on other sites More sharing options...
jib Posted June 20, 2008 Author Share Posted June 20, 2008 <td>Source:</td> <td><input name="Source" type="radio" value="Recruiter" /> Recruiter</td> </tr> <tr> <td> </td> <td><input type="radio" name="Source" value="School" /> School</td> </tr> for the radio, now if $source = recruiter i want recruiter to be default checked <select name="School_Type" id="School_Type"> <option>Private Academy</option> <option>Public School</option> <option>Camp</option> <option>English Village</option> <option>University</option> <option>Other</option> </select> for drop box if $School_Type = Camp I want camp to be the default value etc Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569908 Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 then I will do like this $School_Type=$_POST['School_Type']; $School_Type_aray[]="Private Academy"; $School_Type_aray[]="Public School"; $School_Type_aray[]="Camp"; $School_Type_aray[]="English Village"; $School_Type_aray[]="University"; $School_Type_aray[]="Other"; echo "<select name='School_Type' id='School_Type'>"; for($i=0;$i<count($School_Type_aray);$i++){ $selected=""; if($School_Type_aray[$i]==$School_Type){ $selected="selected"; } echo "<option value=".$School_Type_aray[$i]." ".$selected.">".$School_Type_aray[$i]."</option>"; } echo "</select>"; same kind of thing for radio. ** Dont use same name for textbox and radio !! Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569912 Share on other sites More sharing options...
bluejay002 Posted June 20, 2008 Share Posted June 20, 2008 first place a value... then compare an if()... if it hits... echo selected. <?php $select = 2; ?> <select name="School_Type" id="School_Type"> <option value=1<?php if(1 == $select) echo " selected";?>>Private Academy</option> <option value=2<?php if(2 == $select) echo " selected";?>>Public School</option> <option value=3<?php if(3 == $select) echo " selected";?>>Camp</option> <option value=4<?php if(4 == $select) echo " selected";?>>English Village</option> <option value=5<?php if(5 == $select) echo " selected";?>>University</option> <option value=6<?php if(6 == $select) echo " selected";?>>Other</option> </select> not really the best solution but would do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569913 Share on other sites More sharing options...
jib Posted June 20, 2008 Author Share Posted June 20, 2008 Drop menu's worked perfectly Any ideas for the radio? Im going to try doing it with the same principle as the last one and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569923 Share on other sites More sharing options...
jib Posted June 20, 2008 Author Share Posted June 20, 2008 it worked much <3 Quote Link to comment https://forums.phpfreaks.com/topic/111059-solved-default-values-to-form-fields-set-by-php-variables/#findComment-569925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.