On Aug 29, 2006, at 8:54 PM, Mungbeans wrote:

> Here is my code so far:
>
> <html>
> <head>
> <script type="text/javascript"
>   src="jquery.js"></script>
> <script type="text/javascript">
> $(document).onready(
>       $(document.getElementsById("sendmail"))
>         .set("onclick", "validate()").set("type", "button")
>
> );
>
> function validate() {
>       alert ('validated');
> }
> </script>
> </head>
> <body>
> <form>
> <input
> type="submit" name="sendmail" id="sendmail"
> value="SEND" class="button" />
> </form>

Hi Mungbeans, :)

First thing to change is your first line. You can wrap your onclick  
events in the jQuery $(document).ready() instead.
Then, you can refer to DOM elements the way you would in CSS. So  
instead of $(document.getElementsById("sendmail")) you can have  
something like this: $("#sendmail"). (Oh, and by the way, it should  
have been getElementById, singular).

I'm not sure about the rest of what you're trying to do, but you'll  
probably want to add an "action" attribute to the form element as a  
fall back in case js is disabled and use PHP or some other server- 
side language to take care of things.

Now, back to making the alert work with jQuery, here is what the code  
might look like:

  $(document).ready(function() {
      $("#sendmail").click( function() {
        validate();
      });
  });

    function validate() {
      alert('validated');
    }

Of course, if you don't want to stop the default event on click,  
you'll have to put "return false;" after "validate();" (both without  
quotation marks).

Let me know if that works for you.
___________________
Karl Swedberg
www.englishrules.com




_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to