...

View Full Version : How to creat a real 'option' ?



tenshou
10-28-2002, 05:59 PM
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.

beetle
10-28-2002, 09:36 PM
This what you need?
<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>

tenshou
10-29-2002, 01:24 AM
Yes !
It is work that I want.
Thank you very much !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum