jQuery square brackets

Hi,

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

<html>
<form>
<input type="text" name="form[name]" />
<input type="text" name="form[email]" />
<button id="submit">
</form>


// in jQuery
$("#submit").click(function( ) {
   // how do I get the data from the form?
});


$("#submit").click(function( ) {
  alert($("input:text[name='form[name]']").val());
});

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.

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:


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

The attribute starts with selector and [url=“http://api.jquery.com/attribute-ends-with-selector/”]attribute ends with selector can be useful tools as well.