EVENT_HORIZON Posted September 8, 2011 Share Posted September 8, 2011 I'm just attempting to learn how PHP handles things and I can't quite wrap my head around how to apply Selected to the final Option and show the Traits for the Character based on the Selected Option. I understand this might need POST, if it does, I would appreciate a bit of help on how I would set this up as POST since I didn't think a drop down required a submit button. $character= array (array(Name=>"Barry","Class"=>"Fighter",Level=>1,Str=>10,Dex=>10,"Int"=>10),array(Name=>"Lindehar","Class"=>"Ranger",Level=>1,Str=>10,Dex=>10,"Int"=>10),array(Name=>"Verelden","Class"=>"Mage",Level=>1,Str=>10,Dex=>10,"Int"=>10)); print "Select a Character:<br /><select>"; foreach($character as $array_num) { foreach($array_num as $char_trait=>$trait_value) { if($char_trait==Name) { $selected_value=""; $generated_chars="<option selected=".$selected_value." value='".$char_trait."'>".$char_trait.": ".$trait_value."</option>"; print $generated_chars; if($selected_value=/".$char_trait.": Barry"/") { foreach($char_trait=="Barry") { print "<h4>".$char_trait.": ".$trait_value."</h4>"; } } } } } print "</select><p />"; Quote Link to comment https://forums.phpfreaks.com/topic/246678-option-selected-from-php-generated-dropdown/ Share on other sites More sharing options...
Pikachu2000 Posted September 8, 2011 Share Posted September 8, 2011 The <select> field needs a name attribute, and how are you planning to send a value anywhere if it isn't submitted somehow? Quote Link to comment https://forums.phpfreaks.com/topic/246678-option-selected-from-php-generated-dropdown/#findComment-1266691 Share on other sites More sharing options...
EVENT_HORIZON Posted September 8, 2011 Author Share Posted September 8, 2011 The <select> field needs a name attribute, and how are you planning to send a value anywhere if it isn't submitted somehow? I understand it needs to be submitted but I thought that you could just add POST to the dropdown, is this not correct? Quote Link to comment https://forums.phpfreaks.com/topic/246678-option-selected-from-php-generated-dropdown/#findComment-1266694 Share on other sites More sharing options...
Pikachu2000 Posted September 8, 2011 Share Posted September 8, 2011 Not so much, no. If you're looking to update the page based on the <select> field changing, without actually having to submit and reload the page, you would need to look into an AJAX solution. Quote Link to comment https://forums.phpfreaks.com/topic/246678-option-selected-from-php-generated-dropdown/#findComment-1266695 Share on other sites More sharing options...
nilansanjaya Posted September 8, 2011 Share Posted September 8, 2011 if you want to do it with pure php ( and little bit of javascript. not ajax ) just submit the form to the same page , on the onchange method of the select, using javascript, then capture the values on the top and do what you want to do <select name="select_name" onChange="document.form_name.submit();"> Quote Link to comment https://forums.phpfreaks.com/topic/246678-option-selected-from-php-generated-dropdown/#findComment-1266732 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.