Jump to content


drop down menu help


1 reply to this topic

#1 recordlovelife

    Young Padawan

  • Members
  • Pip
  • 83 posts
  • Gender:Male
  • Location:New Jersey

Posted 12 January 2007 - 02:32 PM

So I have a drop down going from 1 - 25. I want it so if you choose "1". 1 div will appear with a text area for a name and a text area for a comment will appear. If i choose "2", 2 of them will show up.

Im assuming I need to use JavaScript to toggle the divs on and off. And im guessing the drop downs value is going to be the variable to input into the JS to tell it how many of the same divs to open.


But now, since i will be saving the inputted information, each inputted name and comment will have to have a unique ID so that i can call upon a specific entry number and it's info (for example, i need to at random, be able to obtain the comment from #12).



I think I have the concept but not the grasp of coding to do it. Little push would be great...


thanks
frank

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 January 2007 - 02:09 AM

I'd use DOM modification so that the use doesn't have to load all 25 divs just to use 2 of them. Using the innerHTML property along with a pre-wrote JS template of the form would probably be easiest.

i.e.
<script>
function update_form(num){
	form = document.forms[0];
	for(i=0; i < num; i++){
		form.innerHTML += '<input type="text" name="name_'+i+'" value=""><br>'
					   +'<textarea name="comment_'+i+'" rows="5" cols="20"></textarea><br>';
	}
}
</script>

<form method="post" action="/foo.php">
   <select name="select_box">
	   <option value="1">1</option>
	   <!-- ... -->
	</select>
</form>
Not 100% that will work, but it's a push.

p.s. Quirksmode.org is probably the best place i've ever seen to learn about JS, DOM, and event handling. I highly recommend it if you're having problems. You will have to search a bit... it's not exactly organized in the best fassion, but a google search of their site helps narrow things down significantly.

Edited by rc69, 13 January 2007 - 02:11 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users