Jump to content


Photo

javascript <BUTTON> submits form when I don't want it to


  • Please log in to reply
4 replies to this topic

#1 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 21 June 2006 - 08:04 PM

I have a form and have a < BUTTON> with the 'onClick' event. When I click the button it clears a textarea in the form with this 'document.getElementById('daform').db_query.value=' ' ". My problem is that when I put the button inside of < FORM> tags it will submit the form after running the javascript. But when I have it out of the < FORM> tag it will just clear the text and not submit the form. Can I put the button in the < FORM> tag and still have it not submit the form? How?

Thanks
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 21 June 2006 - 08:07 PM

try adding
return false;
to the onClick

#3 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 21 June 2006 - 08:10 PM

Hey thanks. I was returning 0 instead of 'false'. It works now
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#4 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 21 June 2006 - 08:12 PM

Awesome No problem!

#5 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 21 June 2006 - 08:50 PM

You can also use
<input type="button" value="Clear" />

This won't submit the form.

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users