SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery .val() quetion

    Hello forums how do I get the value of a submit button in Jquery using the val() function:

    I have a form

    <form id="myForm" action="blahblah" method="blahblah">

    <!-- input checkboxes here -->

    <input type="image" src="myImage1" class="del" name="submit" value="delete" />
    <input type="image" src="myImage2" class="del" name="submit" value="restore" />
    <input type="image" src="myImage3" class="del" name="submit" value="empty" />
    </form>

    Code JavaScript:
    $(document).ready(function() {
    $('#myForm').submit(function() {
     var value = $('input.del').val(); 
     alert(value);
        return false;
    });
     
    });

    I have this script but it only returns "delete" when I click either the "restore" and "empty" it still returns "delete". I'm pretty sure I missed a jQuery Voodoo here . Please help . stuck for hours

    Thanks
    Don't Panic

  2. #2
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    googleing for answers I found that I should use the attributes instead of the values :

    Code JavaScript:
     $(document).ready(function() {
            $('.del').click(function() {
                alert($(this).attr('value'));
            });
        });

    Cheers!
    Don't Panic


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •