Welcome to WebmasterWorld Guest from 54.167.155.147

Forum Moderators: open

Message Too Old, No Replies

<Button onclick()> not working

Newbie beating head on keyboard

   
5:48 pm on Sep 1, 2006 (gmt 0)

10+ Year Member



My <Button>'s keep submitting as a form and they don't run the onclick="Blah()". Should I not use the <Button>'s? Got a good site recomendation with v e r y s i m p l e examples?

Many Thanks!
M

6:22 pm on Sep 1, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Make sure it is of type [w3.org] "button" instead of "submit".
6:37 pm on Sep 1, 2006 (gmt 0)

10+ Year Member



Wow, that works but seems a little redundant <Button Type="button" id="button" Name="Button" Value="Button">Button</button>

So, now how do I access the "...>Button</b..." value/content/what?

Thanks Tons and "Damn Your Fast!"
M

6:05 pm on Sep 2, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I didn't even realize it was the button [w3.org] element. The first link I gave was for the <input type="button"> element. Here nor there, you got your resolution.

How do you attain the value? Pass it in your "onclick" attribute.

<button type="button" value="My button value" onclick="alert(this.value)">Button</button>
6:14 pm on Sep 2, 2006 (gmt 0)

10+ Year Member



The: <form><Button>Buton</button></form>. still submit's the form when clicked. Is there a way to avoid that, I don't want to submit the form. (I'd like to do it through AJAX)
6:17 pm on Sep 2, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The <button> element defaults to a type="submit" (see last link provided) unless you specify otherwise. Make sure you are setting the type="button" and it won't submit on you.
6:56 pm on Sep 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you just need to put: return false; at the end of the onclick. Example:

<input type="submit" value="Whatever" onclick="someFunction(); return false;" />