homepage Welcome to WebmasterWorld Guest from
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

<Button onclick()> not working
Newbie beating head on keyboard

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

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!



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

Make sure it is of type [w3.org] "button" instead of "submit".


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

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!"


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

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)

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)

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)

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

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

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