Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need some more helpppp!!!

    Hi,

    Well I have this code..

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <script language="JavaScript" type="text/javascript">
    var noRows=0;

    function addTextBox(select){
    var ids = ['roomtype','datestart','dateend','rate'];
    var container = document.getElementById('TextBoxes');
    var nu = select.options[select.selectedIndex].value;
    for(;nu--;noRows++){
    for(var k=0,id; id=ids[k]; k++) container.appendChild(createTextBox(id+noRows));
    container.appendChild(document.createElement('br'));
    }
    var oSel = document.createElement('select')
    var sVal =['single','double','triple','quadruple'];
    oSel.setAttribute('name','sel'+nu);
    for(var i=0;i<sVal.length;i++){
    var oOpt = document.createElement('option');
    var oTxt = document.createTextNode(sVal[i]); oOpt.setAttribute('value',sVal[i]);
    oOpt.appendChild(oTxt);
    oSel.appendChild(oOpt);
    }
    container.appendChild(oSel); container.appendChild(document.createElement('br'));
    }


    function createTextBox(id)
    {
    var box = document.createElement('input');
    box.type = 'text';
    box.size = '15';
    box.id = box.name = id;
    return box;
    }
    </script></head>

    <body>
    <form name="form" action="index3.php" method="post">
    <select name="AddTextBox" size="1" onchange="addTextBox(this);" >
    <option value="0">Add row</option>
    <option value="1">One Row</option>
    <option value="2">Two Row</option>
    <option value="3">Three Row</option>
    <option value="4">Four Row</option>
    </select>

    <div id="TextBoxes" ></div>
    <input type="submit">
    <?

    foreach ( $_POST as $fieldName => $fieldValue)
    {
    echo "Field Name: $fieldName, Field Value: $fieldValue<br>";
    }
    ?>
    </body>
    </html>

    Basically it generates a 4 text boxes (one row) and one drop down box if I choose add one row. But If I choose add 2 rows it genrates 8 text boxes and and only one drop down box. Where as I want it to generate a droop down box on every row added

    2) When I submit only the first frop down box value is shown and no other drop down box value are shon.

    Does any one know what i am doing wrong here ?

    thanks
    Apurva M

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Try:

    PHP Code:
    function addTextBox(select){
    var 
    ids = ['roomtype','datestart','dateend','rate'];
    var 
    container document.getElementById('TextBoxes');
    var 
    nu select.options[select.selectedIndex].value;
    for(;
    nu--;noRows++){
    for(var 
    k=0,idid=ids[k]; k++) container.appendChild(createTextBox(id+noRows));
    container.appendChild(document.createElement('br'));
    var 
    oSel document.createElement('select')
    var 
    sVal =['single','double','triple','quadruple'];
    oSel.setAttribute('name','sel'+nu+noRows);
    for(var 
    i=0;i<sVal.length;i++){
    var 
    oOpt document.createElement('option');
    var 
    oTxt document.createTextNode(sVal[i]); oOpt.setAttribute('value',sVal[i]);
    oOpt.appendChild(oTxt);
    oSel.appendChild(oOpt);
    }
    container.appendChild(oSel); container.appendChild(document.createElement('br'));
    }

    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •