1

This submit button works in both Safari and Chrome but not IE9 or FF9.

Submit button -

 <img type="submit" src="lib/send_feedback.jpg" border="0" class="feedback-submit-img" onClick="javascript: validate(); return false;"/>

Related jQuery -

// Submit form to next page
function submitForm() {
//   document.forms["feedbackform"].submit();
    document.feedbackform.submit();
}
// Submit form and validate email using RFC 2822 standard
function validateEmail(email) { 
    // Modified version original from: http://stackoverflow.com/a/46181/11236
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
// Return true if email field is left unchanged
function originalText(email){
    var defaultMsg;
    defaultMsg = "Enter your email address (optional)";
    if(defaultMsg == email){
        return true;    
    }
    return false;
}
// Verify or decline with error message
function validate(){
    $("#result").text("");
    var email = $("#email").val();
    if ((validateEmail(email)) || originalText(email)) {
        w.value = screen.width;
        h.value = screen.height;
        submitForm();
    } else {
        $("#result").text(email + " is not a valid email.");
        $("#result").css("color", "red");
    }
    return false;
}
$("form").bind("submit", validate);

Also for what it's worth when I alter the submit button to be more basic to ensure it submits the hidden field that w and h are suppose to update are not filled in.

Here is the entire code and the CSS

Eric
  • 565
  • 1
  • 8
  • 25

1 Answers1

3

type isn't a valid attribute of the img tag: https://developer.mozilla.org/En/HTML/Element/Img

Instead I think you want a <input type="image" /> tag: https://developer.mozilla.org/en/HTML/Element/Input.

The <img type="submit" /> didn't work for me either but using a <input type="image" /> did: http://jsfiddle.net/HXrNb/1/

You can then just bind the validate() function to the submit event for the form:

$('form').on('submit', function () {
    ...
    if ((validateEmail(email)) || originalText(email)) {
        ...
        return true;
    } else {
        ...
        return false;
    }
});
Jasper
  • 75,717
  • 14
  • 151
  • 146
  • Doh! This was it, thank you so much for your assistance. This oversight absolutely was the problem, I suppose Chrome and Safari were correcting/compensating for this error. Thank you again for the help. – Eric Jan 27 '12 at 18:34