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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to creat a real 'option' ?

    I want to creat a table to save my DNS' data.
    Now i can use 'DOM' to creat 'input' and 'select' and 'option',
    but the select and option have problems.
    I can't see their names and values on brower.
    someone can help me?


    <html>
    <head>
    <script language="javascript">
    function add()
    {
    var ItemName = (document.test.length - 1)/2;
    if(ItemName >10 ){
    alert(" just can add 10");
    }else{
    var NodeToAddChild = document.getElementById('dncontent');
    var NewTextField = document.createElement('INPUT'); NewTextField.name = "dncontent" + ItemName;
    NodeToAddChild.appendChild(NewTextField);
    var NewTextNode = document.createTextNode (' IN ');
    NodeToAddChild.appendChild(NewTextNode);

    var NewTextField2 = document.createElement('SELECT');
    NewTextField2.name = "dntype";
    NodeToAddChild.appendChild(NewTextField2);

    var NewOption = document.createElement('OPTION');
    NewOption.value = "A";
    NewOption.value = "CNAME";
    NewOption.value = "N";
    NewOption.value = "MX";
    NewOption.value = "PTR";
    NewTextField2.appendChild(NewOption);

    var NewTextField3 = document.createElement('INPUT');
    NewTextField3.name = "corresponding" + ItemName;
    NodeToAddChild.appendChild(NewTextField3);

    var NewBR2 = document.createElement('BR');
    NodeToAddChild.appendChild(NewBR2);
    }
    document.test.max.value = ItemName;
    }

    </script>
    </head>

    <body>
    <table border="1">
    <form method="get" action="2.php" name="test">
    <input type="hidden" name=max value="1">
    <tr>
    <td>value</td><td>in</td><td>type</td>
    </tr>
    <tr>
    <td colspan="3">
    <span id="dncontent">
    <input type="text" name=dncontent1>
    IN
    <select name="named"></opton>
    <option value="">please choose a type</opton>
    <option value="A">A</opton>
    <option value="CNAME">CNAME</opton>
    <option value="NS">NS</opton>
    <option value="MX">MX</opton>
    <option value="PTR">PTR</opton>
    </select>
    <input type="text" name=dntype1><br>
    </span>
    </td>
    </tr>


    <tr>
    <td colspan="3" align="center">
    <input type="button" value="add" onclick="add()">
    </td>
    </tr>

    <tr>
    <td colspan="3"> <input type="submit"></td>
    </tr>
    </form>
    </table>
    </body>
    </html>


    I am very sorry because my English is very bad.
    I don't use english for a long time.
    I just can use very easy english to describe my questions.
    I hope eveyone can understand my questions and help me.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This what you need?
    Code:
    <html>
    <head>
    <script language="javascript">
    function add()
    {
    var ItemName = (document.test.length - 1)/2;
    if(ItemName >10 ){
    alert(" just can add 10");
    }else{
    var NodeToAddChild = document.getElementById('dncontent');
    var NewTextField = document.createElement('INPUT'); NewTextField.name = "dncontent" + ItemName;
    NodeToAddChild.appendChild(NewTextField);
    var NewTextNode = document.createTextNode (' IN ');
    NodeToAddChild.appendChild(NewTextNode);
    
    var NewSelect = document.createElement('SELECT');
    NewSelect.name = "dntype";
    
    addOption(NewSelect, 'A', 'A');
    addOption(NewSelect, 'CNAME', 'CNAME');
    addOption(NewSelect, 'N', 'N');
    addOption(NewSelect, 'MX', 'MX');
    addOption(NewSelect, 'PTR', 'PTR');
    
    NodeToAddChild.appendChild(NewSelect);
    
    var NewTextField3 = document.createElement('INPUT');
    NewTextField3.name = "corresponding" + ItemName;
    NodeToAddChild.appendChild(NewTextField3);
    
    var NewBR2 = document.createElement('BR');
    NodeToAddChild.appendChild(NewBR2);
    }
    document.test.max.value = ItemName;
    }
    
    function addOption(sel, val, txt) {
    	var o = document.createElement("OPTION");
    	var t = document.createTextNode(txt);
    	o.setAttribute("value",val);
    	o.appendChild(t);
    	sel.appendChild(o);
    	}
    
    </script>
    </head>
    
    <body>
    <table border="1">
    <form method="get" action="2.php" name="test">
    <input type="hidden" name=max value="1">
    <tr>
    <td>value</td><td>in</td><td>type</td>
    </tr>
    <tr>
    <td colspan="3">
    <span id="dncontent">
    <input type="text" name=dncontent1>
    IN
    <select name="named"></opton>
    <option value="">please choose a type</opton>
    <option value="A">A</opton>
    <option value="CNAME">CNAME</opton>
    <option value="NS">NS</opton>
    <option value="MX">MX</opton>
    <option value="PTR">PTR</opton>
    </select>
    <input type="text" name=dntype1><br>
    </span>
    </td>
    </tr>
    
    
    <tr>
    <td colspan="3" align="center">
    <input type="button" value="add" onclick="add()">
    </td>
    </tr>
    
    <tr>
    <td colspan="3"> <input type="submit"></td>
    </tr>
    </form>
    </table>
    </body>
    </html>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes !
    It is work that I want.
    Thank you very much !


  •  

    Posting Permissions

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