|
Have a form which is having two combo boxes. My requirement
is that when I chose a particular value in combo, then another combo should
get filled onchange event of the first combo. Example, the first combo
has department names and the second combo should get filled with the sub-department
names which are stored in the database. I do not want to submit my form.
How to achieve this?
Sample Coding: <script> <!-- var plabels = new Array(); var parents = new Array(); var family = new Array();
parents[0] = new Array( "Parent 0 - children 1",
parents[1] = new Array( "Parent 1 - children 1",
parents[2] = new Array( "Parent 2 - children 1",
parents[3] = new Array( "Parent 3 - children 1",
parents[4] = new Array( "Parent 4 - children 1",
for (i=0; i<5; i++) { plabels[i] = "Parent " + i; }
function fillParents() { var pList = document.frm.parent; for (i=0; i<plabels.length; i++) { pList.options[i+1] = new Option(plabels[i], i); }
} function fillChilds() { var pObj = document.frm.parent; var cObj = document.frm.child; var parent = pObj.options[pObj.selectedIndex].value; var childs = parents[parent]; cObj.length = 0;
for (i=0; i<childs.length; i++) { cObj.options[i+1] = new Option(childs[i], i); } cObj.options[0] = new Option("- Please specify -", "", false, true); }
//--> </script> <p>Dynamic pull-down boxes</p> <form name="frm" method="post"> <p>Parent: <select name="parent" onchange="fillChilds()"> <option value="">- Please specify -</option> </select> <p>Children: <select name="child"> <option value="">- Please specify -</option> </select>
</form> <script> <!--
fillParents(); //--> </script> |
|
See also
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|