Just wondering if I could get a hand.
I've found this code that I want to use in my form:
When I run it by itself it works.
When I put it into chronoforms I get the error message saying that "myform" is undefined.
I put this into the HTML code:
And this into the Javascript Code:
[code] calculate = function(totalElement)
{
if (totalElement)
{
var calculation = '';
var overall = '';
var fields = new Array();
var theElement = document.getElementById(totalElement);
var userInputs = myform.elements;
var the_type = '';
for (var f = 0; f < userInputs.length; f++)
{
if (userInputs[f].className=='special_value')
{
if (userInputs[f].type=='select-one')
{
if(userInputs[f].options[userInputs[f].selectedIndex].value)
{
fields[f] = userInputs[f].options[userInputs[f].selectedIndex].value;
}
else
{
fields[f] = 0;
}
}
else if(userInputs[f].type=='radio' ||
userInputs[f].type=='checkbox')
{
if (userInputs[f].checked)
{
fields[f] = userInputs[f].value;
}
else
{
fields[f] = 0;
}
}
else
{
if (userInputs[f].value)
{
fields[f] = userInputs[f].value;
}
else
{
fields[f] = 0;
}
}
}
}
for (var i=0; i<fields.length; i++)
{
calculation += fields[i];
if (i!=fields.length-1)
{
calculation += '+';
}
}
if (calculation!='')
{
overall = eval(calculation).toFixed(2);
}
if (overall!='')
{
theElement.innerHTML = '
I've found this code that I want to use in my form:
When I run it by itself it works.
When I put it into chronoforms I get the error message saying that "myform" is undefined.
I put this into the HTML code:
<form name="myform">
<h2>Input Fields</h2>
<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value"
type="text" name="price"> <Br/>
<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value"
type="text" name="price2"> <Br/>
<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value"
type="text" name="price4"> <Br/><Br/>
<h2>Radio Button</h2>
<input onClick="calculate('total');" name="price111"
type="radio" value="100" class="special_value">100<br>
<input onClick="calculate('total');" name="price111"
type="radio" value="200" class="special_value">200<br>
<input onClick="calculate('total');" name="price111"
type="radio" value="300" class="special_value">300<br>
<input onClick="calculate('total');" name="price111"
type="radio" value="400" class="special_value">400<br><br>
<h2>Checkboxes</h2>
<input onClick="calculate('total');" name="price112"
type="checkbox" value="400" class="special_value">400<br>
<input onClick="calculate('total');" name="price112"
type="checkbox" value="600" class="special_value">600<br>
<input onClick="calculate('total');" name="price112"
type="checkbox" value="700" class="special_value">700<br>
<input onClick="calculate('total');" name="price112"
type="checkbox" value="900" class="special_value">900<br><br>
<h2>Drop Down Menu</h2>
<select onChange="calculate('total');" name="price5" class="special_value">
<option value="0"></option>
<option value="900">9k</option>
<option value="500">5k</option>
<option value="400">4k</option>
</select>
<br /><br /><br />
<div id="total"></div>
<input onClick="calculate('total');" type="button" name="button" value="re-calculate">
</form>
And this into the Javascript Code:
[code] calculate = function(totalElement)
{
if (totalElement)
{
var calculation = '';
var overall = '';
var fields = new Array();
var theElement = document.getElementById(totalElement);
var userInputs = myform.elements;
var the_type = '';
for (var f = 0; f < userInputs.length; f++)
{
if (userInputs[f].className=='special_value')
{
if (userInputs[f].type=='select-one')
{
if(userInputs[f].options[userInputs[f].selectedIndex].value)
{
fields[f] = userInputs[f].options[userInputs[f].selectedIndex].value;
}
else
{
fields[f] = 0;
}
}
else if(userInputs[f].type=='radio' ||
userInputs[f].type=='checkbox')
{
if (userInputs[f].checked)
{
fields[f] = userInputs[f].value;
}
else
{
fields[f] = 0;
}
}
else
{
if (userInputs[f].value)
{
fields[f] = userInputs[f].value;
}
else
{
fields[f] = 0;
}
}
}
}
for (var i=0; i<fields.length; i++)
{
calculation += fields[i];
if (i!=fields.length-1)
{
calculation += '+';
}
}
if (calculation!='')
{
overall = eval(calculation).toFixed(2);
}
if (overall!='')
{
theElement.innerHTML = '