stijn0713 Posted February 28, 2012 Share Posted February 28, 2012 Hello, I can't seem to find a solution: I ask the subscriber to enter (1) how many children they have (2) from those children, how many still live at home (3) if they select children, they need to fill in their names, sex and date of birth Therefor i have 2 select boxes in a form. The first one selects the number of children and onchange, textfields equal to the number selected appear for filling in the childrens names, as well for the sex and dob. This works properly. Secondly, i wanted to make dependent select boxes from the number of children and the number of children still living at home so that the choices for the number of children staying home are from 0 to the number of selected children. I also tested this code in a seperate document and it worked fine. The problem comes when i want to display both functions in one file. i used to syntax: onchange = "function1();function2();" please help Here is the relevant code: 2 js functions in the head tags function dropdownlist(listindex) { document.formname.subcategory.options.length = 0; switch (listindex) { case "1" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); break; case "2" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); break; case "3" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); break; case "4" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); break; case "5" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); break; case "6" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); break; case "7" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); break; case "8" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); break; case "9" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); document.formname.subcategory.options[10]=new Option("9","9"); break; case "10" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); document.formname.subcategory.options[10]=new Option("9","9"); document.formname.subcategory.options[11]=new Option("10","10"); break; } return true; } function addKindForms(aantal) { if (aantal != "-") { var output = ""; output = output + "<table cellpadding='2' cellspacing='0'>"; output = output + "<tr><td><b>Naam:</b></td><td><b>Geslacht:</b></td><td><b>Geboortedatum:</b></td><td></td><td></td></tr>"; for(i=1;i<=aantal;i++) { output = output + "<tr><td><input type='text' name='kind"+i+"_name' size='15' value=''></td><td><select name='kind"+i+"_sex'><option value='m'>jongen</option><option value='f'>meisje</option></select></td><td><input type='text' name='kind"+i+"_gebdatum' size='15' value='dd/mm/yyyy'></td></tr>"; } output = output + "</table>"; document.getElementById("kindforms").innerHTML = output; } } in the body (the form and the select boxes): <form method="POST" name"formname"> <td>Aantal: <label for="aantalkinderen"></label> <select name="aantalkinderen" id="aantalkinderen" onchange="addKindForms (this.value); dropdownlist(this.options[this.selectedIndex].value);"> <option value="">-</option> <option value="1"<?php if ($_POST['aantalkinderen'] == "1") { echo "selected"; } ?>>1</option> <option value="2"<?php if ($_POST['aantalkinderen'] == "2") { echo "selected"; } ?>>2</option> <option value="3"<?php if ($_POST['aantalkinderen'] == "3") { echo "selected"; } ?>>3</option> <option value="4"<?php if ($_POST['aantalkinderen'] == "4") { echo "selected"; } ?>>4</option> <option value="5"<?php if ($_POST['aantalkinderen'] == "5") { echo "selected"; } ?>>5</option> <option value="6"<?php if ($_POST['aantalkinderen'] == "6") { echo "selected"; } ?>>6</option> <option value="7"<?php if ($_POST['aantalkinderen'] == "7") { echo "selected"; } ?>>7</option> <option value="8"<?php if ($_POST['aantalkinderen'] == "8") { echo "selected"; } ?>>8</option> <option value="9"<?php if ($_POST['aantalkinderen'] == "9") { echo "selected"; } ?>>9</option> <option value="10"<?php if ($_POST['aantalkinderen'] == "10") { echo "selected"; } ?>>10</option> </select> waarvan thuiswonend: <script type="text/javascript" language="JavaScript"> document.write('<select name="subcategory"><option value="">-----</option></select>') </script> <div id="kindforms"></div> </td> </form> Quote Link to comment https://forums.phpfreaks.com/topic/257920-calling-2-functions-onchange/ Share on other sites More sharing options...
codefossa Posted February 29, 2012 Share Posted February 29, 2012 Just create a function that will run all you're wanting. function doThis() { aFunc(); anotherFunc(); } Quote Link to comment https://forums.phpfreaks.com/topic/257920-calling-2-functions-onchange/#findComment-1322208 Share on other sites More sharing options...
Amit20 Posted February 29, 2012 Share Posted February 29, 2012 What you are doing thats absolutely correct. But i suggest you follow this link. http://www.javascriptkit.com/javatutors/eventaction.shtml Hope it helps!!! Quote Link to comment https://forums.phpfreaks.com/topic/257920-calling-2-functions-onchange/#findComment-1322414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.