[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 07-13-2008, 04:33 PM   #1 (permalink)
NamePros Regular
 
Join Date: Jun 2008
Posts: 224
0.00 NP$ (Donate)

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.

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, 06:33 PM   #2 (permalink)
NamePros Member
 
Join Date: Sep 2006
Posts: 87
100.00 NP$ (Donate)

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, 02:30 PM   #3 (permalink)
NamePros Regular
 
Join Date: Jun 2008
Posts: 224
0.00 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:02 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85