Results 1 to 13 of 13

Thread: HTML Image to submit form <Resolved />

  1. #1

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    HTML Image to submit form <Resolved />

    hello people i havent done this in years and forgot

    how do you use an image as a submit button for a form ?

    in this case its a Go button for searching
    eg:

    Code:
    <form action="search.asp?Mode=1" method="post" name="test">
    <input name="txtsearch" type="text" size="10">
    
    <!-- this is normal command button yeah-->
    
    <input type="submit" name="Submit" value="Go">
    
    <!-- i want an image for the button to submit the form-->
    </form>
    Last edited by señorbadger; May 25th, 2004 at 03:24 AM.

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    maybe just give the submit button a src attribute.
    otherwise try using the <button><img src="" /></button>
    This instead. But then I don't know how to make it submit without using JavaScript. To make JavaScript submit a form you do:
    document.test.submit()

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Something similar to this:
    Code:
    <form name="searchForm" action="page.php" method="post">
         <input type="text" name="searchTerm" />
         <img src="image.jpg" onclick="document.searchForm.submit();" alt="Click here to search" />
    </form>
    Last edited by TomGibbons; May 24th, 2004 at 06:35 AM.

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    this will work, but also you can use the <input .../> tag. I've seen it done before.

  5. #5

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193
    yeah ive seen it before with the input tag too and i used to do it that way

  6. #6
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Code:
    <form name="searchForm" action="untitled-2.htm" method="post">
         <input type="text" name="searchTerm" />
         <input type="image" name="image" src="image.jpg" alt="click here" />
    </form>
    It passes the co-ordinates of where you clicked if I remember correctly.

  7. #7
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    if you change type="image" to type="submit" I think you'll get what you need.

  8. #8
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Firstly; Changing the type to submit will turn the input into a button, which is not what he asked for.

    Secondly; Why? What's wrong with what I posted?

  9. #9
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    He asked how to turn an image into a submit button. ie he wants a submit button which is an image. Unless of course I miss-understood it.

    Nothing is wrong with what you posted, I just don't think that's what was being asked for.

  10. #10
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Close, he wants to use an image as a submit button. So you've two choices; You can put some Javascript in an image's onclick to submit the form. So that it is now functioning as a submit button.

    Or, you could set the input's type to image and give it a src property. When you click on the image, it submits the form. I thought that it passed the co-ords of where you clicked, but I just tested it and it doesn't appear to do so. Either way, the image is functioning as a submit button.

  11. #11
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Ah yes I see you were right. I just had the wrong thing in my head, I should have checked before posting. sorry about that.

  12. #12

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193
    thanks for the help people ill give it a try

    thanks again

  13. #13
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Originally posted by Acidic
    Ah yes I see you were right. I just had the wrong thing in my head, I should have checked before posting. sorry about that.
    No worries

    Originally posted by señorbadger
    thanks for the help people ill give it a try

    thanks again
    No worries

Posting Permissions

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



Click Here to Expand Forum to Full Width