Results 1 to 2 of 2

Thread: Need help fixing return value in function..

  1. #1
    Join Date
    Mar 2009
    Posts
    43
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help fixing return value in function..

    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:

    Code:
    <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~

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!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>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •