Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/257920-calling-2-functions-onchange/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.