Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    OM2
    OM2 is offline
    New Coder
    Join Date
    Apr 2012
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Trouble accessing a form element

    I'm having trouble accessing a form element
    I need to have a hidden field the value of which I need to pass through
    I've seen lots of sample code, but just can't get it to work for what I need

    I have some code that I adapted
    I have:

    var $contactform = $(this).closest('.contact-form-shop');

    A few lines down I have:


    var customername = $contactform.find('input[name="customername"]').val();
    var email = $contactform.find('input[name="email"]').val();
    var extradetails = $contactform.find('textarea[name="extradetails"]').val();

    The above work fine!

    I've added the following field:

    <input type="hidden" name="shopName" value="XyZ" style="display: none;">

    And I've tried things like:

    var shopName = $contactform.find('shopName').val();

    Console.log says the variable is undefined

    Where am I going wrong?

    Thanks


    OM

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Code:
    var shopName = window.document.getElementsByName('shopName')[0].value;
    Or give it an ID;
    var shopName = window.document.getElementById('shopName').value;
    It looks like the code you have is for some library maybe you aren't using.

  • Users who have thanked DrDOS for this post:

    OM2 (07-06-2012)

  • #3
    OM2
    OM2 is offline
    New Coder
    Join Date
    Apr 2012
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts
    thanks. that works a treat


  •  

    Posting Permissions

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