SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery square brackets

    Hi,

    does anyone know how do I get the post data from html in jQuery which contains square brackets?

    PHP Code:
    <html>
    <
    form>
    <
    input type="text" name="form[name]" />
    <
    input type="text" name="form[email]" />
    <
    button id="submit">
    </
    form
    PHP Code:
    // in jQuery
    $("#submit").click(function( ) {
       
    // how do I get the data from the form?
    }); 
    I Dunno LOL \(_o)/

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    $("#submit").click(function( ) {
      alert($("input:text[name='form[name]']").val());
    });

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want the data of the form in format that can be sent to a server-side language, check jQuery documentation for serialize() method.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    If they don't want to express the full details in the selector, you can just make use of the attribute contains selector.

    So if you're sure that the page contains only one form field with email in its name:

    Code javascript:
    alert($('input[name*="email"]).val());

    The attribute starts with selector and attribute ends with selector can be useful tools as well.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •