SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using an image for submit button with JavaScript

    I'm a JavaScript newbie. I'm trying to use a custom button for a form submission. Everything looks and works wonderfully except in IE 7 (it works fine in Safari and Firefox). But in IE7 when I click on the image I get a message saying: Error: object expected. If I click OK, the form submits just fine. But, of course, I can't have the error message come up each time. Here's my code. If anyone has any suggestions as to what I need to add I would be very grateful. Thanks very much.

    <a href="javascript:document.pkform.submit()" onmouseover="document.pkform.submitbutton.src='images/sendformover_30.jpg'" onmouseout="document.pkform.submitbutton.src='images/sendform_30.jpg'" onclick="return val_form_this_page()"><img src="images/sendform_30.jpg" alt="Send Form" name="submitbutton" id="submitbutton" width="270" height="34" /></a>

  2. #2
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 Actions for 1 click may be confusing browser

    What I am seeing in this code is that you have two actions on the object for 'click'. The first is in the default action for href="javascript:document.pkform.submit()" that will automatically trigger when the link is clicked. The second is the onclick method, onclick="return val_form_this_page().

    Try moving the 'return val_form_this_page();' function call to the href, like this, href="javascript:val_form_this_page();" (drop the return, because I don't think it's necessary). Then, put the "document.pkform.submit()" within the "val_form_this_page()" function. This way, you only have one action triggered from the click event and you'll be able to use the val_form_this_page() function to perform whatever actions you wish before submitting the form.

    This should solve your problem.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you!

    Yes, that seemed to work. Thank you very, very much.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A better solution would be to use an input with a type of image:

    <input type="image" src="...">

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I tried that

    I tried that first and was unable to get IE7 to display the image properly, so I went to this solution.


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
  •