PDA

View Full Version : Need help fixing return value in function..



ShadowIce
05-17-2009, 01:25 PM
Hi all. :) I have done some deep research on returning strings to an element id, and on for loops, but for some reason i cant seem to return the value of the text box i created. Instead, it returns a value of "NaN". The function that is returning "NaN" is "ztest()".

Here is the code as follows:


<script>
<!--Hide from old browsers
var x1 = 0;
var x2 = 0;
var num=4;
function ztest(){
if('document.test.forms.blah+x1.onClick'){
if(document.getElementById('boxes').innerHTML != null || document.getElementById('boxes').innerHTML != ""){
document.getElementById("zztest").innerHTML += document.test.forms.blah+x1.value;
}else{
alert('enter!');
}
}
}
function zsubmit(){
if('document.forms.test.zzsubmit.onClick'){
x2++;
}
alert(x2);
}
-->
</script>
<form name="test">
<p align="Center">
<script>
<!--Hide from old browsers
function addbox(){
if('document.forms.test.add.onClick'){
x1++;
}
document.getElementById('boxes').innerHTML += 'Name '+x1+': <input type="text" onClick="ztest();" name="blah'+x1+'"><br>n';
}
document.write('<span id="zztest" style="background-Color: #44CFFC; width: 400px; height: 50px;"></span><script>for(var x=1;x<=2;x++){document.write('<br>');}</script>n');
document.write('<input type="button" name="add" value="Add box" onClick="addbox();">n');
document.write('<input type="button" name="zzsubmit" onClick="zsubmit();" value="Submit"><br>n');
document.write('<a href="javascript:window.opener=false, window.close('-1');">Exit</a><br>n');
document.write('<span id="boxes" style="background-Color: #44CFFC; width: 400px; height: 25px;"></span><br>n');
-->
</script>
</p>
</form>

I simply need the text box to return the value of the box to the element.

thanks!

~SI~

vwphillips
05-18-2009, 09:55 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<script>
<!--Hide from old browsers
var x1 = 0;
var x2 = 0;
var num=4;
function ztest(){
if('document.test.forms.blah+x1.onClick'){
if(document.getElementById('boxes').innerHTML != null || document.getElementById('boxes').innerHTML != ""){
document.getElementById("zztest").innerHTML +=document.getElementsByName('blah')[x1-1].value;
}else{
alert('enter!');
}
}
}
function zsubmit(){
if('document.forms.test.zzsubmit.onClick'){
x2++;
}
alert(x2);
}
-->
</script>
<form name="test">
<p align="Center">
<script>
<!--Hide from old browsers
function addbox(){
if('document.forms.test.add.onClick'){
x1++;
}
document.getElementById('boxes').innerHTML += 'Name '+x1+': <input type="text" onClick="ztest();" name="blah" ><br>n';
}
document.write('<span id="zztest" style="background-Color: #44CFFC; width: 400px; height: 50px;"></span><script>for(var x=1;x<=2;x++){document.write(\'<br>\');}</script>');
document.write('<input type="button" name="add" value="Add box" onClick="addbox();">n');
document.write('<input type="button" name="zzsubmit" onClick="zsubmit();" value="Submit"><br>n');
document.write('<a href="javascript:window.opener=false, window.close(\'-1\');">Exit</a><br>n');
document.write('<span id="boxes" style="background-Color: #44CFFC; width: 400px; height: 25px;"></span><br>n');
-->
</script>
</p>
</form>
</body>

</html>