NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page How to create a "reactive" form?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-13-2008, 05:33 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Jun 2008
Posts: 231
thenext88 will become famous soon enough
 



How to create a "reactive" form?


I'm looking at creating some type of reactive form, where if an option selected, the options below will depend on what the person selected...

For example... The Form has two options A and B.
????: NamePros.com http://www.namepros.com/programming/492397-how-to-create-a-reactive-form.html

If option A is selected, then a new option menu shows below displaying sub-options C and D. If option B is selected then a new option menu shows below displaying sub-options E and F instead.

Pretty much what I'm looking at is...

If A is selected -> Display html code for options C and D
If B is selected -> Display html code for options E and F

So I would need to pull the value that is selected, and display code based on which value is selected without refreshing the page.

I would assume Javascript... but I know very little if of this. I would appreciate any help/guidance. Thanks.
__________________
http://www.lucid.me (free online dream journal with stats tacking available)
http://www.luhd.com
http://www.logical2012.info (the next doomsday, or not)
thenext88 is offline  
Old 07-13-2008, 07:33 PM   #2 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



This is tested in Firefox, but not IE.

Code:
<html>
<head>

<script type='text/javascript'>
function showHide() {
  var which = document.theForm.option1[0].checked?1:2;
  document.getElementById('option_' + which).style.display = '';
  document.getElementById('option_' + (Math.abs(2 - which) + 1)).style.display = 'none';
}
</script>

</html>

<body>

<form action='script.php' method='POST' name='theForm'>
<div>
  <input type='radio' name='option1' value='1' onclick='showHide();' /> Show Option 2
</div>
<div style='padding-bottom: 10px;'>
  <input type='radio' name='option1' value='2' onclick='showHide();' /> Show Option 3
</div>

<div id='option_1' style='display: none;'>
  <input type='radio' name='option2' value='1' /> Option 2 Choice 1 <br />
  <input type='radio' name='option2' value='2' /> Option 2 Choice 2
</div>

<div id='option_2' style='display: none;'>
  <input type='radio' name='option3' value='1' /> Option 3 Choice 1 <br />
  <input type='radio' name='option3' value='2' /> Option 3 Choice 2
</div>

<div>
  <input type='submit' value='Submit'>
</div>

</form>

</body>
</html>
Bruce_KD is offline  
Old 07-14-2008, 03:30 PM THREAD STARTER               #3 (permalink)
NamePros Regular
Join Date: Jun 2008
Posts: 231
thenext88 will become famous soon enough
 



Hey thanks for the script. Wasn't quite what I needed (needed drop down menus) but I still appreciate it. I actually did a bit more searching, and found something called "dynamic form options" which is exactly what I needed, so my problem is solved. Thanks again.

By the way it works in IE.
__________________
http://www.lucid.me (free online dream journal with stats tacking available)
http://www.luhd.com
http://www.logical2012.info (the next doomsday, or not)
thenext88 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:57 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger