Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help debugging a probably only small error...

    first of all, hello all

    i found this forum while running out of ideas and being extremely desperate to fixing a probably small javascript error in a script. the script is supposed to open a small form window that allows the user to input an email address and update it to proceed. the form item is initially unchecked, but as the user clicks it and enter his email address, it updates the value of the email address and the box becomes "checkable". the problem is that with both IE and firefox, the box doesn't close again, doesn't get checkable and basically doesn't work. in the firefox debugging console, I found the following error:

    Error: document.getElementById(input_array[i]) is null
    Source File: sell_item.php
    Line: 1106
    does anyone have an idea what could be wrong?

    the part responsible in the javascript for this section is:

    Code:
    <script language="javascript">
    	function pg_popup_open(id)
    	{
    		if (document.getElementById(id).style.display == 'block')
    		{
    			document.getElementById(id).style.display = 'none';			
    		}
    		else
    		{
    			document.getElementById(id).style.display = 'block';
    		}
    		return false;
    	}	
    	
    	function pg_update_settings(id, input_array)
    	{
    		xmlHttp=GetXmlHttpObject();
    		
    		if (xmlHttp==null)
    		{
    			alert ("Browser does not support HTTP Request");
    			return;
    		}
    
    		var url    = '' + 'ajax_files/direct_payment_box.php';
    		var action    = url + '?id=' + id + '&user_id=' + 100001;
    
    		var chk_disabled = false;
    		for ( var i in input_array )
    		{
        		action += '&' + input_array[i] + '=' + document.getElementById(input_array[i]).value;
        		
        		if (document.getElementById(input_array[i]).value == '')
        		{
        			chk_disabled = true;
        		}
    		}		
    		
    		xmlHttp.onreadystatechange = function() { 
    			if (xmlHttp.readyState == 4)
    			{
    				var response = xmlHttp.responseText;
    			}
    		};
    		xmlHttp.open("GET", action, true);
    		xmlHttp.send(null);		
    		
    		document.getElementById('checkbox_' + id).disabled = chk_disabled;
    		if (chk_disabled == true)
    		{
    			document.getElementById('checkbox_' + id).checked = false;
    		}
    		document.getElementById(id).style.display = 'none';
    		return false;
    	}
    </script>
    and the html code that is supposed to pop up the box is:

    Code:
    <input type="checkbox" name="payment_gateway[]" id="checkbox_pg_paypal" value="1"  disabled>
    <span class="contentfont"><a href="javascript:;" onclick="pg_popup_open('pg_paypal');">PayPal</a></span>
    <script language="javascript"> var array_pg_paypal = new Array(); array_pg_paypal[0] = 'pg_paypal_email';</script>
    <div class="smallfont"><b>PayPal Email Address</b><br>
    <input type="text" name="pg_paypal_email" id="pg_paypal_email" value="" /></div>
    <div align="right"><input type="button" value="Proceed" onclick="pg_update_settings('pg_paypal', array_pg_paypal);" /></div>
    i understand this is asking a lot, but if someone has a spare second that is a javascript guru, i promise i will name my first born after you!! lol


  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Try changing this line:
    Code:
    		for ( var i in input_array )
    to this:
    Code:
    		for ( var i = 0; i < input_array.length; ++i  )
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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