Jump to content

javascript select dropdown


stijn0713

Recommended Posts

Hi

 

I'm trying to create a form where people first select the number of children they have, and then a table should appear where they fill in the extra information (name, sex, dob) about every child.

 

The code works except for that i don't know how to add the year of the date of birth of every child with a loop. Appartly i cannot use php in javascript?

 

Any solutions? thanks!

 

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><select name='kind"+i+"_gebdatumdag'><option value=''></option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'> 8</option><option value='9'>9</option><option value='10'>10</option> <option value='11'> 11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option></select></td><td><select name='kind'+i+'_gebdatummaand'><option value=''></option><option value='1'>jan</option><option value='2'>feb</option></select></td><td><select name='kind'+i+'_gebdatumjaar'><option value=''></option><?php for ($y=date('Y');$y>=(date('Y')-125);$y--){if($_POST['bdaykind_jaar']==$y){$selected='selected';}echo'<option value=''.$y.'' '.$selected.'>'.$y.'</option>';$selected = '';}?></select></td></tr>";

}

output = output + "</table>";
document.getElementById("kindforms").innerHTML = output;

}
}

Link to comment
Share on other sites

that's right you cannot run php in javascript but you can print out javascript from php, however. In your javascript where you have a select for the years you will need to change that to a javascript for() statement instead.

Link to comment
Share on other sites

Can i please get more code help! Here is my problem: http://trippledee.org/signup.php. If you look at 'kinderen' (children), they fill in f.e. 5, then 5 new boxes should appear generated with javascript.

 

My question remains: how can i populate the dropdows of the children's birthday?!

 

PLEASE HELP

 

 

this is up till now my javascript:

 

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><select name='kind"+i+"_gebdatumdag'></select></td><td><select name='kind"+i+"_gebdatummaand'></select></td><td><select name='kind"+i+"_gebdatumjaar'></select></td></tr>";

}


output = output + "</table>";
document.getElementById("kindforms").innerHTML = output;

}
}

 

 

this is the HTML

 

<td>Kinderen:</td>
        <td>Aantal: 
          <label for="aantalkinderen"></label>
          <select name="aantalkinderen" id="aantalkinderen" onchange="addKindForms (this.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:
<input type="text" name="kindthuiswonend" id="kindthuiswonend" size="10" value="<?php echo $_POST['kindthuiswonend']?>" />
        
        <div id="kindforms"></div> 
       
        </td>

 

 

Link to comment
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.