Yodaman
10-16-2003, 02:47 PM
I am trying to create a form using the clone function. The form has a couple of radio buttons and everytime the form clones itself the radio buttons are still named the same thing. I need to name them differently so when I answer a question in the first form, it is not affected by the answer in the second.
ie. when i choose an option in first form, then go to the second form to choose the same exact option, it "steals" the answer from the first form...and that is because they are named teh same thing. I need to know how to name them differently when I am cloaning them. I got help from someone in regards to this, but it does not seem to work. The code is below if anyone can help me out. Thanks in advance.
<script>
var PolicyNum = 1; //create a global policy number
function addPolicy()
{
PolicyNum ++
numPolicies = PolicyNum
newSpan = document.getElementById("mainPolicy").cloneNode(true)
newSpan.id = "span" + numPolicies
newSpan.firstChild.innerHTML = "<h3>Policy #" + numPolicies + "</h3>"
document.getElementById("policyDIV").appendChild(newSpan)
cleanNode("span" + numPolicies)
}
function deleteThis(inObj){
thisRow = document.getElementById("span" + inObj)
thisRow.removeNode(true)
}
function cleanNode(nodeName){
//cleans out input boxes in new node
spanNode = document.getElementById(nodeName)
allInputs = spanNode.getElementsByTagName("input")
for (x=0; x<allInputs.length; x++){
allInputs[x].name = allInputs[x].name + PolicyNum
allInputs[x].value = ""
}
}
</script>
<div id="policyDIV">
<span id="mainPolicy" style="border: solid blue 3px; width:400; height: 250;">
<h3>Primary Policy</h3>
<table border=1 >
<tr>
<td><input name="polNumber"></td>
<td><input name="polName"></td>
</tr>
</table>
<table border=1>
<tr>
<td><input type="radio" name="someDataField" value=2></td>
<td><input type="radio" name="someDataField" value=1></td>
<td><input name="whatever"></td>
</tr>
</table>
</span>
</div>
<input type="button" onClick="addPolicy()" value="Add">
If you have no idea what I was trying to explain, run this code. Choose a radio option. Then click add, and choose a radio option. You will notice that the option you choose for the first radio button isnt there anymore!
ie. when i choose an option in first form, then go to the second form to choose the same exact option, it "steals" the answer from the first form...and that is because they are named teh same thing. I need to know how to name them differently when I am cloaning them. I got help from someone in regards to this, but it does not seem to work. The code is below if anyone can help me out. Thanks in advance.
<script>
var PolicyNum = 1; //create a global policy number
function addPolicy()
{
PolicyNum ++
numPolicies = PolicyNum
newSpan = document.getElementById("mainPolicy").cloneNode(true)
newSpan.id = "span" + numPolicies
newSpan.firstChild.innerHTML = "<h3>Policy #" + numPolicies + "</h3>"
document.getElementById("policyDIV").appendChild(newSpan)
cleanNode("span" + numPolicies)
}
function deleteThis(inObj){
thisRow = document.getElementById("span" + inObj)
thisRow.removeNode(true)
}
function cleanNode(nodeName){
//cleans out input boxes in new node
spanNode = document.getElementById(nodeName)
allInputs = spanNode.getElementsByTagName("input")
for (x=0; x<allInputs.length; x++){
allInputs[x].name = allInputs[x].name + PolicyNum
allInputs[x].value = ""
}
}
</script>
<div id="policyDIV">
<span id="mainPolicy" style="border: solid blue 3px; width:400; height: 250;">
<h3>Primary Policy</h3>
<table border=1 >
<tr>
<td><input name="polNumber"></td>
<td><input name="polName"></td>
</tr>
</table>
<table border=1>
<tr>
<td><input type="radio" name="someDataField" value=2></td>
<td><input type="radio" name="someDataField" value=1></td>
<td><input name="whatever"></td>
</tr>
</table>
</span>
</div>
<input type="button" onClick="addPolicy()" value="Add">
If you have no idea what I was trying to explain, run this code. Choose a radio option. Then click add, and choose a radio option. You will notice that the option you choose for the first radio button isnt there anymore!