Jump to content

Option Selected from PHP generated dropdown


EVENT_HORIZON

Recommended Posts

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 />";

Link to comment
Share on other sites

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();">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.