We help IT Professionals succeed at work.

Drop down menu with multiple values

kayz
kayz asked
on
In my asp page, I have created a drop down menu and with a radio button. How do i configure in asp script or any vb/java script to display a number of radio button base on the selection made in the drop down menu. I will give list to drop menu as 1, 2, 3, and 4. When people click on 2, means that 2 radio buttons will be displayed, and if they click 3 then 3 radio buttons will come out an so forth. How to configure that??

Can somebody let me know, I really appreciate that

Thank you so much
Comment
Watch Question

Commented:
Try this:

<html>
<head>
<script language="JavaScript">
function showRadios(frm, lst) {
 var i, j = parseInt(lst.value);
 var o;
 alert(j)
 for (i = 1; i <= j; i++) {
  o = document.createElement("<input>");
  o.type = "radio";
  frm.appendChild(o);
 }
}
</script>
</head>
<body>
<form name="frm">
<select name="lst" onchange="javascript:showRadios(document.frm, this);">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
</body>
hi,

I believr, there are two ways of going about it.

If you can be sure that your application will be used only in IE5x then you could go for the CREATE ELEMENT method to dynamically generate the radio buttons according to the user selection.

Otherwise , since the possible otions seem to be known beforehand (1-4), so you could create four radios and then control their display( show/hide) properties according to the user selection.

Any particular reason why this question is listed in ASP and not javascript, since your requirement  is primarily client-side code, if I am not to be corrected.

Regds,
Saif

Author

Commented:
I will try your code, thanks a lot...i really appreciate it

Author

Commented:
Is it same if I use another control like other drop down menu? Because I use another drop down menu to make another selection. The scenario is like this, people will choose number of option in the first drop down menu, if they choose 2 meaning another 2 drop down menu will come out. And in respective drop down menu, I put another option/list of selection. All the list of selection is actually a data in database. Do I need to write do while.. loop for every drop down menu in my asp page?

Commented:
If data for each new dropdown will be coming from the database, it'll be best to submit the form after each change of selection from the first drop down.

Just add onchange="javascript:document.submit()" to your <select> and generate the HTML codes from the server side. Since you're on the server already, it will be best to resolve for everything that you will display there. This way, you won't need much JavaScript.

Otherwise, you can try the dropdown menu parent-child relationship technique. You will have to expose your database as JavaScript arrays when you do this (if it is not much of a security issue).

Explore More ContentExplore courses, solutions, and other research materials related to this topic.