homepage Welcome to WebmasterWorld Guest from 54.226.21.57
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Ho do you emulate submit button click on an image
just using a href?
Clark

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3064407 posted 2:49 pm on Aug 29, 2006 (gmt 0)

Hello,

I've got an image meant to look like a submit button. I'd like when the image is clicked to get the same click the browser gives when clicking submit.

While I can emulate this by doing something like:

<form action="whatever">
<input type="hidden" name="hello" value="goodbye">
<input type="image" src="pathtoimage" name="do" value="submit">
</form>

I'm "missing" the alt tag displaying, plus it's so much easier to just do

<a href="url"><img src="pathtoimage"></a>

Is there a javascript to cause a click when pressed? Preferably inline so I can just do an "onclick"=?

 

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3064407 posted 4:13 pm on Aug 29, 2006 (gmt 0)

I think what you already have is correct, if you are wanting an image to submit a form then using:

<input type="image"....

is the way to go. This is a submit btn. It behaves the same as an <input type="submit"... and you can also add a alt and title attributes to give your users some popup text.

If, however, you want to submit a form that is on the page, but from an image (click) which is not within that form, then you can do...

<form name="myform"...
Form stuff...
</form>

<img src="mybutton.gif" onclick="myform.submit();">

But personally, I would stick to the first example, with type="image" if possible.

----------------

ASIDE: I've found that a submit button with type="image" is not passed to PHP, key/value pairs?! Am I missing something?!

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3064407 posted 6:12 pm on Aug 29, 2006 (gmt 0)

Anyone reading can ignore that last ASIDE note above, as I've found the answer was actually in the question... I was missing the value attribute from the <input> tag, so naturally the key/value pair wasn't generated! Oops!

Clark

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3064407 posted 6:57 pm on Aug 29, 2006 (gmt 0)

I must not have been clear. I can get this to work if I use the "form" trick. (although specifying "alt" text is not getting me the tooltip popup text for some reason).

What I'm trying to do is achieve the same affect as if it was a form, but having it only as an <a href> link.

In other words, it's just an image attached to a link. I still want to hear the "click" sound.

I hope it was clearer.

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3064407 posted 10:21 pm on Aug 29, 2006 (gmt 0)

You'll need to specify a title="Popup text here" attribute in your <input> tag to get a popup message.

But it's the 'click' *sound* you are after?! My machine does not make any sound when I click on a (submit) button, whether it's in a form or not, and my machine is pretty much in its default configuration as far as that sort of thing goes.

Whether a users machine makes a click sound on a standard HTML form submit is very much down to the users individual machine - I think!

Clark

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3064407 posted 10:46 pm on Aug 29, 2006 (gmt 0)

Really? I've had lots of machines, they all "click"....

but that "title" thing is helpful, thanks!

If someone else got some "click javascript", will still be happy for it :)

Rambo Tribble

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3064407 posted 1:54 am on Aug 30, 2006 (gmt 0)

The click sound is probably a feature of the browser you are using and its configuration. For instance, on my machine Firefox is generally silent while Konqueror makes all manner of odd grunts, clicks and squeals.

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3064407 posted 10:24 am on Aug 30, 2006 (gmt 0)

Hhhmmm, yeah... just out of interest... I do get a click sound from IE5 on Win98 when clicking on links, but *not* on form submits. (The system sounds on that machine have probably been configured in the past.) In all other cases, I get no click sound at all... Win98 - FF, Opera7, N4(!). WinXP - IE6, FF, Opera8. (And I've got the volume turned way high!)

I did wonder about ASCII code 7 (maybe &#7) which is historically a 'beep' but that doesn't seem to work!

The other possibility maybe to embed a sound (a small .WAV file) into a page with EMBED/BGSOUND and somehow trigger the sound (change the SRC attribute perhaps) via the onclick event of the link. But it seems like a lot of work for something which 'might' work on 'some' machines - and people could find annoying.

HeadBut

10+ Year Member



 
Msg#: 3064407 posted 5:50 pm on Aug 30, 2006 (gmt 0)

Is it possible to catch a mouse click while a script is running, like an AJAX update, then play a sound to indicate the erant click will not be responded to?

Thanks
M

Clark

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3064407 posted 7:12 pm on Aug 30, 2006 (gmt 0)

I just tested it and it turns out my brain "remembered" a click sound and I assumed it was in Firefox, but it was a memory from ie. The brain really plays weird tricks on you. Or I'm just getting old..

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved