SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image button doesn't submit form, but hitting enter does

    Hi,

    I have the following code for a newsletter signup. The form works when the user enters their email address and hits enter, but if the submit the form using the image or a link, it prompts them with a message saying the email address is invalid.


    Any ideas what would cause this?


    Thanks

    PHP Code:
    (function(a){var b={g:function(){var d=document.cookie.split(";");for(var e=0;e<d.length;e++){var f=d[e];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf("euCookieLaw")==0){return f.substring("euCookieLaw".length,f.length)}}return null},s:function(d){var c=new Date();c.setTime(c.getTime()+315532800000);document.cookie="euCookieLaw="+d+"; expires="+c.toGMTString()+"; path=/"}};a.extend({cookieLaw:function(c){var e={impliedConsent:true,title:"Our Cookie Policy",shortMessage:"<h3>Sign up for Special Offers</h3><p><img src=\"/beta/images/small_tick.png\" /> Discount Codes and Promotions<br /><img src=\"/beta/images/small_tick.png\" /> Receive Special Offers<br /><img src=\"/beta/images/small_tick.png\" /> Latest News and Competitions</p><p><strong>Enter your email to signup:</strong></p><form action=\"action.php" method=\"post\" id=\"newsletter_form\"><input type=\"text\" id=\"email\" onfocus=\"javascript:this.value =(this.value == 'Your email address...')?'':this.value;\" onblur=\"javascript: this.value=(!this.value)?'Your email':this.value;\" class=\"email\" maxlength=\"4000\" name=\"EMAIL\" value=\"Your email\" size=\"23\" /><a href=\"#\" onclick=\"var form = document.getElementById('newsletter_form'); Marketing.OptIn(form); return false\" title=\"Sign Up for offers\" class=\"button\">signup</a><input type=\"hidden\" name=\"EMAIL_REQUIRED\" value=\"T\" /><input type=\"hidden\" name=\"EMAIL_DATATYPE\" value=\"email\" /><input type=\"hidden\" name=\"agent_code_REQUIRED\" value=\"T\" /><input type=\"hidden\" name=\"agent_code_DATATYPE\" value=\"text\" /><input type=\"hidden\" id=\"newsletter_agentCode\" name=\"agent_code\" value=\"$ref_code\" /></form>",longMessage:"Cookies are small text files held on your computer. They allow us to give you the best browsing experience possible and mean we can understand how you use our site.",onAccepted:function(){}},d=b.g();c=a.extend(e,c);if(d==null){a.notify({inline:true,html:"<h3>"+c.title+"</h3><p>"+c.shortMessage+'</p><p id="euCookieLongMessage" style="display: none;">'+c.longMessage+'</p><p id="euCookieButtonContainer">'+(!c.impliedConsent?'<a id="euCookieAccept" class="btn primary" href="#">I Accept</a>':"")+' <a class="btn" id="euCookieMoreInfo" href="#">More Info</a> </p>',close:(!c.impliedConsent?a("#euCookieAccept"):"Close"),onComplete:function(){a("#euCookieMoreInfo").click(function(){if(a("#euCookieLongMessage").is(":hidden")){a(this).text("Less Info");a("#euCookieLongMessage").fadeIn(250);a.notify("resize",a(this).parents(".notification"))}else{a(this).text("More Info");a("#euCookieLongMessage").fadeOut(250,function(){a.notify("resize",a(this).parents(".notification"))})}});if(c.impliedConsent){b.s("implied");c.onAccepted.call(this)}},onCleanup:function(){b.s("accepted");c.onAccepted.call(this)}})}else{c.onAccepted.call(this)}}})})(jQuery); 

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ebsolutions View Post
    The form works when the user enters their email address and hits enter, but if the submit the form using the image or a link, it prompts them with a message saying the email address is invalid.

    Any ideas what would cause this?
    What would cause that is if the image or link is triggering other code before the form is submitted.

    It looks as if the shortMessage part of your script has a syntax error around the action part of it too.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •