Jump to content

Dropdown menu selection makes text appear help?


emmery1185
 Share

Recommended Posts

Hello, I'm very new to javascript but I think its is the solution to a problem I've been having. What I'm trying to do is have a number of paragraphs appear, within the form tags, when an option in a drop down menu from a form is selected. For instance if 'option A' is selected then a paragraph will appear saying "you have selected option A". Another paragraph will appear saying "option A is the first option" and so on and each paragraph is different depending on the option. I have tried an number on ways, including methods from the tutorials, and none of them work, Please help.

Link to comment
Share on other sites

Heres a slimmed down version of what I've done so far

<head><script type="text/javascript"><!--function human(){document.getElementById("bonus").innerHTML="Humans have a total of 25 points to generate from, not the usual 20.";}//--></script></head><body><form id="character" name="character" method="post" action="characteremail.php">Name:<input type="text" name="playername" size="50" /><br />E-Mail:<input type="text" name="email" size="50" /><br />Character Name:<input type="text" name="character" size="50" /><br />Race:<select name="race">	  <option value="Blank" selected="selected">Select Race</option>	  <option onchange="human()" value="human">Human</option>	  <option value="dwarrow">Dwarrow</option>	  <option value="troll">Troll</option>	  <option value="halfling">Halfling</option><option value="hob">Hob</option>	  <option value="sithi">Sithi</option>	  <option value="goblin">Goblin</option>	  <option value="kobold">Kobold</option>   <option value="norn">Norn</option>	  <option value="ogre">Ogre</option>	  <option value="chimera">Chimera</option>	  <option value="changling">Changling</option></select><br />Racial Bonuses:<p id="bonus"> </p></form></body>

Link to comment
Share on other sites

Place the onchange event within select element and send the value of selected option

Race:<select name="race" onchange="human(this.value)">

look at the valur returned and if 'human' then send info to specific element id

function human(selectedvalue){document.getElementById("bonus").innerHTML="";if(selectedvalue=="human"){document.getElementById("bonus").innerHTML="Humans have a total of 25 points to generate from, not the usual 20.";}}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...