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 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Simple javascript not working with IE9

    Hi, I have a small javascript function which isn't functioning in IE9. There's lots of other complicated functions which seem fine so why this doesn't work is beyound me, don't even know where to start.

    There's a form with a dialog box which opens when someone clicks a button, after they fill out the form on the dialog box it closes and is suppose to refresh a dropdown box on the main form. The function is called using the "onsubmit" on the dialog form.

    This is the form tag.
    PHP Code:
    <form id="fromaddressform" name="fromaddressform" action="addfromaddresspopup.php" onsubmit="refreshfromselect()" method="post"
    This is the function
    Code:
    function refreshfromselect() {	
    	if(ClientFromLocationID.value == "")
    	{
    		$(ClientFromLocationID).load('fromlocationajax.php');
    	}
    	else {
    		//do nothing
    	}	
    }
    If I remove the if statement and only have the .load line it still does nothing. I don't think its the php file as it uses the same code when the main form loads and it works correctly.

    Any ideas would be appreciated.

  • #2
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    It also can't deal with the following.

    Code:
    function validateCreateShipmentForm()
    {
    	    if(ClientFromLocationID.value.length == 0)
    	
    	{
    		alert('Please select a ship from location!');
    	}
    	
    	    if(ClientToLocationID.value.length == 0)
    	
    	{
    		alert('Please select a ship to location!');
    	}
    	
    	else if (!validatePieces() || !validatePackageType() || !validateWeight() || !validateServiceType() || !validateReadyAtDate() || !validateReadyAtTime() || !validateIfClosed())
    	{
    	// do nothing
    	}
    	else
    	{
    	document.forms["createshipment"].submit();
    	}
    }
    Damm browsers why can't they all just get along!

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,166
    Thanks
    23
    Thanked 601 Times in 600 Posts
    Code:
    function refreshfromselect() {	
    	if(ClientFromLocationID.value == "")
    	{
    		$(ClientFromLocationID).load('fromlocationajax.php');
    	}
    	else {
    		//do nothing
    	}	
    }
    If your not going to do anything in the ELSE section of an IF statement don't use it!
    Code:
    $(ClientFromLocationID).load('fromlocationajax.php');
    Looks to be jquery and it won't work S/B:
    Code:
    $("#ClientFromLocationID").load('fromlocationajax.php');
    Your if statement does not work.
    Try this
    Code:
    if($("#ClientFromLocationID").val() == "")
    OR
    Code:
    if($("#ClientFromLocationID").text() == "")
    Things might look like this:
    Code:
    <body>
    <div id="ClientFromLocationID"></div>
    <button onclick="refreshfromselect()">PUSH</button>
    
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script type="text/javascript">
    function refreshfromselect() {//alert($("#ClientFromLocationID").val());
    	if($("#ClientFromLocationID").text() == ""){
    		$("#ClientFromLocationID").load('fromlocationajax.php');
    	}
    }
    </script>
    </body>
    P.S. Same errors in second post.

    Are you using javascript or jquery?
    Last edited by sunfighter; 03-18-2014 at 03:16 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Since the form is being submitted and ajax is asynchronous, the ajax call in the onsubmit handler may be aborted when the form submits. If you don't need to submit the form to addfromaddresspopup.php, then you need to return false on the onsubmit handler.
    Code:
    <form id="fromaddressform" name="fromaddressform" action="addfromaddresspopup.php" onsubmit="return refreshfromselect();" method="post">
    Code:
    function refreshfromselect() {	
    	if(ClientFromLocationID.value == "")
    	{
    		$(ClientFromLocationID).load('fromlocationajax.php');
    	}
    	return false;
    }
    I assume that ClientFromLocationID is a valid DOM reference to the select element. If so, then the above js code is correct. But if not (if it's only the id), then you need to do it this way:
    Code:
    function refreshfromselect() {
    	var $location = $('#ClientFromLocationID');
    	if ($location.val() == "")
    	{
    		$location.load('fromlocationajax.php');
    	}
    	return false;
    }

  • #5
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks for the suggestions!

    This fixed the if statements
    Code:
    if($("#ClientFromLocationID").val() == "")
    However for ajax that still doesn't work.

    I'm using both jQuery and javascript and to be honest never know what's what.

    The addfromaddresspopup.php file adds the new address to the database and the fromlocationajax.php queries the database for the companies in the drop down box.

    I'm not sure what valid DOM reference is, ClientFromLocationID is the ID for the drop down box, the name is also ClientFromLocationID.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Is the dialog box in a new window (popup)? And you want to update the dropdown in the main window when the popup is submitted? If yes, then you need to move the refreshfromselect() method from the popup to the main window, then do this:
    PHP Code:
    <form id="fromaddressform" name="fromaddressform" action="addfromaddresspopup.php" onsubmit="opener && !opener.closed && opener.refreshfromselect && opener.refreshfromselect();" method="post"
    Then in the main window:
    Code:
    function refreshfromselect() {
    	var $location = $('#ClientFromLocationID');
    	if ($location.val() == "")
    	{
    		$location.load('fromlocationajax.php');
    	}
    }
    Use the browser's dev tools (F12) to debug and monitor the ajax request.

  • #7
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    no its a jquery dialog box. It slides over the main form and disappears when I close it, sorry for not being clear.

    The dropdown is on the main form and needs the update. It works on the firefox and chrome, just IE9 is having a problem. Not sure about ie10 as my computer won't upgrade for some reason.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Ok, I wonder why the code works in FF and Chrome when you do the ajax request onsubmit. When the form is submitted, the page will redirect to the form action. Can you post more code?

  • #9
    New Coder
    Join Date
    Aug 2013
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I'm back, sorry for the delay. Still have the above problem, I've basically have the site finished as far as programming goes, at least for now and was hoping to solve that issue while doing other things.

    I thought it might be best if I post a link to the site, this way you can see exactly what I'm talking about. The above problem is on the "new delivery" page. Add a new address and you'll see how it magically appears in firefox and google, IE9 isn't into the magic. I have to reload to make it appear.

    www.kool-lics.ca
    User: chaser
    Password: chaser

    Feel free to do whatever, its not live and will be moved to a different domain when it is.

    I also wouldn't mind some feedback, this is the first site I've made with forms and a database.

    The best thing I've done so far was download and run Netsparker and SQL Inject Me (firefox addon) for checking for sql injections. There were tons, every form, every code, lol. I also realized the importance of a good FTP password. I had a basic password that I also used for an account. Netsparker grabbed all the passwords from the db and got into my ftp account and uploaded a file, of course 1and1 saw this and locked my ftp account and sent me an email. So yeah I was quite vulnerable. I wish I knew about permeterized queries, a future update I guess.

    After adding some sanitizing code I've managed to basically secure the db however on a couple forms it fails a few tests on some fields using SQL Inject Me, passes most and for the life of me I can't figure out why, they are exactly the same as ones that completely pass. Is there something I should add to the following sanitizing code that may help?

    PHP Code:
    <?php
    function cleanInput($input) {

      
    $search = array(
        
    '@<script[^>]*?>.*?</script>@si',   // Strip out javascript
        
    '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
        
    '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
        
    '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
      
    );

        
    $output preg_replace($search''$input);
        return 
    $output;
      }
    ?>
    <?php
    function sanitize($input) {
        if (
    is_array($input)) {
            foreach(
    $input as $var=>$val) {
                
    $output[$var] = sanitize($val);
            }
        }
        else {
            if (
    get_magic_quotes_gpc()) {
                
    $input stripslashes($input);
            }
            
    $input  cleanInput($input);
            
    $output mysql_real_escape_string($input);
        }
        return 
    $output;
    }
    ?>


  •  

    Posting Permissions

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