#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7

    Alert() triggered twice in IE


    I have done a bit of Googlin, and have come across similar quite a bit, but most seems to be in relation to submission, or such. I merely wish to run a command when leaving a cell. I have 2 codes below. The first is my original. The second, which I also need help with is a thought to see if instead of using the onClose w/ the datepicker, I would make a function to call via onblur.
    Code:
    $('#finish').datepicker( {
      dateFormat: "mm-dd-yy",
      onClose: function () {
        var dt1 = $('#start').datepicker('getDate');
        var dt2 = $('#finish').datepicker('getDate');
        if (dt2 < dt1) {
          alert('The finish date cannot be prior to the start.');
          setTimeout("$(function(){$('#finish').focus();})",100);
          //$('#finish').datepicker('setDate', dt1);
        }
      }
    });
    Now, if someone can tell me what I am doing wrong here, since I know very basic javascript. I just want to make the function valdate() and call it via onblur="valdate()", but it says that valdate is note defined. Did I create this wrong?
    Code:
    $(document).ready(function() {
      function valdate() {
        var dt1 = $('#start').datepicker('getDate');
        var dt2 = $('#finish').datepicker('getDate');
        if (dt2 < dt1) {
          alert('The finish date cannot be prior to the start.');
          setTimeout("$(function(){$('#finish').focus();})",100);
          //$('#finish').datepicker('setDate', dt1);
        }
      }
    });
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Well, just figured out the function wasn't to be within the $(document).ready(function() { section. Also found out that onblur will not be an option since it will fire when attempting to select a data from the datepicker since that click is outside the field.

    Any other ideas on a way to run my validation that IE might not fire twice?
    Last edited by Triple_Nothing; January 13th, 2014 at 07:52 AM.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    I take it no ideas? :-/
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  6. #4
  7. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Do the validation on submit instead; here is a copy of my login form, you should be able to see how it can fit into your form as it's a pretty basic example (but it works):-

    Code:
    echo "<form name='user_log_in' id='user_log_in' method='post'>";
    echo "<table width='100%'>";
    	echo "<tr>";
    		echo "<td width='25%'>";
    			echo "Enter your username or email address: ";
    		echo "</td>";
    		echo "<td width='75%'>";
    			echo "<input type='text' name='user_code' id='user_code' class='len150'>";
    			echo "<div id='user_code_missing' style='display: none;'>";
    				usernote ("error", "'Username or email address' is missing!", TRUE);
    			echo "</div>";
    		echo "</td>";
    	echo "</tr>";
    	echo "<tr>";
    		echo "<td width='25%'>";
    			echo "Enter your password : ";
    		echo "</td>";
    		echo "<td width='75%'>";
    			echo "<input type='password' name='user_pin' id='user_pin' class='len150'>";
    			echo "<div id='user_pass_missing' style='display: none;'>";
    				usernote ("error", "'Password' is missing!", TRUE);
    			echo "</div>";
    		echo "</td>";
    	echo "</tr>";
    	echo "<tr>";
    		echo "<td width='25%'>";
    			echo "&nbsp;";
    		echo "</td>";
    		echo "<td width='75%'>";
    			echo "<input type='submit' value='Log in' name='submit'> ";
    		echo "</td>";
    	echo "</tr>";
    echo "</table>";
    echo "</form>";
    ?>
    <script>
    <!--
    
    $(document).ready( function() {
    
    	$("#user_log_in").submit(function(){
    		$('#user_code_missing').fadeOut(300);
    		$('#user_pass_missing').fadeOut(300);
    
    		// Ensure both username and password fields are populated
    		if ( $('#user_code').val() == "" ) {
    			$('#user_code_missing').fadeIn(300);
    			return false;
    		}
    		if ( $('#user_pin').val() == "" ) {
    			$('#user_pass_missing').fadeIn(300);
    			return false;
    		}
    	});
    
    	$('#user_code').keyup ( function() {
    		if ( $('#user_code').val() == "" ) {
    			$('#user_code_missing').fadeIn(300);
    		} else {
    			$('#user_code_missing').fadeOut(300);
    		}
    	});
    
    });
    
    //-->
    </script>
    You can see the submit section of the jQuery it does a "return false" if there's any errors in my entries (well, in my case any missing mandatory fields) and that stops the form from being submitted. If there are no errors and the function is allowed to complete, the form is submitted.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Hmmm... I suppose that is an option. I was hoping a more prompt action, but I guess the odds of such are so little, it ain't worth the time. ^_^ Most will prolly use the datepicker anyway, n that cuts off prior dates. Thanks for the idea.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him

IMN logo majestic logo threadwatch logo seochat tools logo