dadamssg Posted March 24, 2009 Share Posted March 24, 2009 i modified a script that initially grabbed the date and had the date selected for a selection list. I made it to were when i exited it because of errors it would still display the users input. I want to do the same thing but with a gender selection. I'm not sure how to modify it though, like if i need to create an array for say $sex[]=array("Male","Female") and then don't know where to go from that...heres the day selector script i modified, that i want to use the same idea. <?PHP $todayDay= $_POST['sday']; //get the day from $today echo "<select name='sday'>\n"; for ($sday=1;$sday<=31;$sday++) { echo " <option value=$sday"; if ($todayDay == $sday ) { echo " selected"; } echo "> $sday\n"; } echo "</select>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/150818-solved-help-with-selection-list/ Share on other sites More sharing options...
dadamssg Posted March 24, 2009 Author Share Posted March 24, 2009 nevermind...played with it and figure it out, maybe not the most efficient but works echo"<select name='sex'>/n"; echo"<option value='male'"; if($_POST['male']=="male") { echo "selected"; } echo">Male\n"; echo"<option value='female'"; if($_POST['female']=="female") { echo "selected"; } echo">Female\n"; echo "</select>\n"; Link to comment https://forums.phpfreaks.com/topic/150818-solved-help-with-selection-list/#findComment-792330 Share on other sites More sharing options...
dadamssg Posted March 24, 2009 Author Share Posted March 24, 2009 k, new problem...i've created a radio button list that i want the same thing, it will remember what the user inputted if an error pops up...this script however won't work with my register script...it says that its a blank even when i select one and click submit...below is the code that displays the radio buttons and then the part that checks to see if nothing is chosen. echo"<input type='radio' name='student' value'yes'"; if($_POST['student']=="yes") {echo"checked='checked'";} echo"/>I'm a student"; echo"<input type='radio' name='student' value'no'"; if($_POST['student']=="no") {echo"checked='checked'";} echo"/>I'm not a student<br>"; if(!isset($_POST['student'])) { $messages[]= "Please select if you are a student.<br>"; } not sure why me name='student' and $_POST['student'] are working together... ??? Link to comment https://forums.phpfreaks.com/topic/150818-solved-help-with-selection-list/#findComment-792340 Share on other sites More sharing options...
dadamssg Posted March 24, 2009 Author Share Posted March 24, 2009 figured this one out two haha, i went about it a much simpler way. just put this in my form <input type='radio' name='student' value='yes'<?php if($_POST['student']=="yes") {echo"checked='checked'";} ?>/>I am a Student <input type='radio' name='student' value='no'<?php if($_POST['student']=="no") {echo"checked='checked'";} ?>/>I am not a Student<br> Link to comment https://forums.phpfreaks.com/topic/150818-solved-help-with-selection-list/#findComment-792350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.