SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    In your for loop, see what the value of input_array is

    (hint: js doesn't automatically update the array value passed in to the "for...in" loop, you'll need to still reference it using the index, in this case "i")
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


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
  •