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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Javacript alert box redirect to false IE9?

    Okay, on my website I have some javascript code I'm using to make the user input required text. If they don't enter info in all the required fields an alert box appears (nothing new)..

    The issue is, when you click okay, it redirects to a page and just says "false." It only does this in IE9.. Chrome has no issues.. Any idea? or resolutions?

    website issue here: https://pcexpresstechs.com/get_started.html



    here is the code:
    Code:
    function verify() {
    var themessage = "You are required to complete the following fields: \n";
    if (document.input.first.value=="") {
    themessage = themessage + " - First Name";
    }
    if (document.input.last.value=="") {
    themessage = themessage + " - Last Name";
    }
    if (document.input.email.value=="") {
    themessage = themessage + " - Email Address";
    }
    if (document.input.phone.value=="") {
    themessage = themessage + " - Phone";
    }
    //alert if fields are empty and cancel form submit
    if (themessage == "You are required to complete the following fields: \n") {
    document.input.submit();
    }
    else {
    alert(themessage);
    return false;
       }
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,564 Times in 2,542 Posts
    It appears that your form name is "input". In that case IE (any version) will barf as input is an HTML keyword. Change the name of the form to myform or something.

    BTW, form validation of the pattern if (document.input.first.value=="") { is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    eaglei22 (08-13-2011)

  • #3
    New Coder
    Join Date
    Jun 2011
    Location
    Algeirs,Algeria
    Posts
    43
    Thanks
    5
    Thanked 3 Times in 3 Posts
    This should happen in any browser because you use javascript: protocol in <a> element, it will be better if you used a submit button inside the form, but if you prefer this method add void 0; after your code in order to not overwrite the content of the page, like this:
    Code:
    <a onmousedown="switchImage('submitImage',5)" onmouseover="switchImage('submitImage',4)" onmouseout="switchImage('submitImage',3)" href="javascript:verify();void 0;">
    
           <img border="0" src="Graphics/buttons/continue1.png" name="submitImage">
    
           </a>

  • Users who have thanked Hamza7 for this post:

    eaglei22 (08-13-2011)

  • #4
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey guys thanks for the quick response.. I actually figured it out.

    return false needed to be changed to event.returnValue=false;


  •  

    Posting Permissions

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