lightyear2000
Programmer
OK so what Ive built so far is a page that has a drop-down menu with various values, this value is then passed to two other fields for addding/subtracting or whatever. As you will se you can add as many fields underneath as you like but as soon as you do, the calculator function becomes disabled? I realise I need to name the new fields underneath somehow to distinguish them from each other but how do I do it??
Thanks in advance.
Here's the code:
<html>
<head>
<title>Adding Values</title>
<script language="JavaScript">
var counter = 0;
<!-- This bit Adds more form fields
function moreFields()
{
counter++;
var newFields = document.getElementById('readroot').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++)
{
var theName = newField.name
if (theName)
newField.name = theName + counter;
}
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
window.onload = moreFields;
function init()
{
moreFields();
}
// End of the Form Field Adder -->
<!-- This bit calculates the Values
function write_this(){
document.funds.output_box1.value = document.funds.input_box.value;
document.funds.output_box2.value = document.funds.input_box.value * 1;
}
// End of the Calcultor Bit -->
</script>
</head>
<body>
<div id="readroot" style="display: none">
<p>
<select name="input_box" id="">
<option value="0">---- Click here to select your Value ----</option>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
<option value="4">Value 4</option>
</select>
<input name="button2" type="button"
onClick="
this.parentNode.parentNode.removeChild(this.parentNode);
" value="Remove">
<input name="output_box1" type="text" value="" size="15">
<input name="output_box2" type="text" value="" size="15">
<br>
</div>
<form action="javascript:write_this()" name="funds" id="funds">
<span id="writeroot"></span>
<input name="button" type="button" onClick="moreFields()" value="Add a Value">
</p>
<p>
<input name="submit" type="submit" value="Calculate">
</p>
</form>
</body>
</html>
Thanks in advance.
Here's the code:
<html>
<head>
<title>Adding Values</title>
<script language="JavaScript">
var counter = 0;
<!-- This bit Adds more form fields
function moreFields()
{
counter++;
var newFields = document.getElementById('readroot').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++)
{
var theName = newField.name
if (theName)
newField.name = theName + counter;
}
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
window.onload = moreFields;
function init()
{
moreFields();
}
// End of the Form Field Adder -->
<!-- This bit calculates the Values
function write_this(){
document.funds.output_box1.value = document.funds.input_box.value;
document.funds.output_box2.value = document.funds.input_box.value * 1;
}
// End of the Calcultor Bit -->
</script>
</head>
<body>
<div id="readroot" style="display: none">
<p>
<select name="input_box" id="">
<option value="0">---- Click here to select your Value ----</option>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
<option value="4">Value 4</option>
</select>
<input name="button2" type="button"
onClick="
this.parentNode.parentNode.removeChild(this.parentNode);
" value="Remove">
<input name="output_box1" type="text" value="" size="15">
<input name="output_box2" type="text" value="" size="15">
<br>
</div>
<form action="javascript:write_this()" name="funds" id="funds">
<span id="writeroot"></span>
<input name="button" type="button" onClick="moreFields()" value="Add a Value">
</p>
<p>
<input name="submit" type="submit" value="Calculate">
</p>
</form>
</body>
</html>