THANKS to all for replying. SOLUTION found: I used a DIV instead of a FORM and serialized every INPUT inside it.
CURRENT FIDDLE CODE: http://jsfiddle.net/MyBZC/
The form:
<form id="sfn" name="sfn">
<input name="datasource" type="hidden" value="TDA">
<input name="staticfields" type="hidden" value="">
<input name="returnfield" type="hidden" value="Complaintinformation_ID">
<input name="returnid" type="hidden" value="Complaintinformation_ID">
eCI ID:<input class="nostyle" type="text" name="id" id="Complaintinformation_ID" style="width:150px;"/>
Complaint number: <input class="nostyle" type="text" name="ecin" id="ecin" style="width:150px;"/>
</form>
The JQuery:
var ds= $("#sfn").serializeArray();
alert(ds);
alerting ds gives me an empty alert box. Can it be the serializeArray() isn't working because this html form is actually inside another form tag?
Unedited real (longer) html output is this:
<form id="searchform_srcSupplier" name="searchform_srcSupplier">
<input name="datasource" type="hidden" value="DEACSQL10_BPCS_DATA">
<input name="from" type="hidden" value="BPCS_AVM">
<input name="where" type="hidden" value="Partner_ID='122'">
<input name="componentname" type="hidden" value="srcSupplier">
<input name="staticstrings" type="hidden" value="Supplier address">
<input name="staticfields" type="hidden" value="LTRIM(RTRIM(VNDAD1))+'<br>'+LTRIM(RTRIM(VNDAD2))+'<br>'+LTRIM(RTRIM(VCITY))+'<br>'+LTRIM(RTRIM(VPOST))+' '+LTRIM(RTRIM(VSTATE))">
<input class="nostyle" name="returnfield" type="hidden" value="VNDNAM">
<input class="nostyle" name="returnid" type="hidden" value="VENDOR_id">
<table ><tr>
<td>
Supplier ID:
</td>
<td>
<input class="nostyle" type="text" name="VENDOR" id="VENDOR" style="width:150px;"/>
</td>
<td>
Supplier name:
</td>
<td>
<input class="nostyle" type="text" name="VNDNAM" id="VNDNAM" style="width:150px;"/>
</td>
</tr><tr>
</tr>
</table>
</form>
(I already tried removing the table from the form)
CURRENT FIDDLE CODE: http://jsfiddle.net/MyBZC/
4 Answers 4
Try this: Working Demo http://jsfiddle.net/tFSdq/ or http://jsfiddle.net/bnTLR/
You need to serialise the input inside container. not the container itself
Hope this fits the need :)
P.S. don't forget to click click me man button to get alert in second demo using serialize and .serializeArray.
code
var ds= $("#sfn input").serializeArray();
alert(ds);
Further see 3 images below which shows what these 2 alerts displays on the values entered. enter image description here
Image 2
enter image description here
Image 3
enter image description here
7 Comments
:) Awesome!!:))add #id like this
var ds= $("#sfn").serializeArray();
alert(ds);
serializeArray() and serialize() both are working for me please check myfiddle
1 Comment
Like you have already figured out, serializeArray() does not work on nested forms since it is illegal HTML as stated in the jQuery docs:
Note that serializeArray() only works on form elements, using this method on another element will not work. Also, this method will not give any results on nested forms, which are illegal in HTML anyway.
You may need to work with serialize() as stated by jhonraymos or use Tas_innit's method.
2 Comments
:) hope it helps you! Hope you are clicking the button to get the alerts.Take a look at this: http://docs.jquery.com/Ajax/serializeArray
it is written over here that...."this method will not give any results on nested forms, which are illegal in HTML anyway"
serialize()I don't know what's the difference but plz try it and also let me know