views:

192

answers:

2

I'm trying to change the src of an image form submit button using an onclick, but it doesn't seem to be working correctly. Am I missing something?

<input class="submit_image" id="my_form_button" onclick="$('my_form_button').src='/images/buttons/submitting.gif'" src="/images/buttons/submit.gif" type="image" /> 

I've also tried using the same JS on the form tag using onsubmit with no luck.

A: 
onclick="this.src='/images/buttons/submitting.gif';"
Babiker
An explanation with that down vote might have been nice.
Babiker
A: 

Perhaps it's an illusion and your form is submitting and refreshing the page before it changes. Try adding a return false; to the end of your onclick statement?

derrickp
That works actually (to change the image), but when I add that the form no longer posts.
james
Then your problem is much more complicated. If you want the form to post but the page to not change, you'll need to do it via AjaxOtherwise you'll need to tell the page with php to change the image if $_POST data exists.
derrickp
I do want the page to change, but for the time it takes to load I wanted the image to change. Unless that's fundamentally not possible.
james
I don't believe there really is any load time unless there's a delay in getting a response from your server.Especially if you're testing locally. Though I suppose there could be a case where the client is slow to process, in which case your code should work without the return false, you probably just won't be able to tell.
derrickp
Ah ok, that was also something I was thinking too. It's just too fast to even show that the image changes.
james