0

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/

asked Oct 15, 2012 at 6:57
3
  • try alerting length of ds so that you may know if anything is serialized or not Commented Oct 15, 2012 at 7:02
  • @Abu: length is 0 (zero). also if I log 'ds' in console, it just gives me a blank line. not even [object] Commented Oct 15, 2012 at 7:04
  • can you try serialize() I don't know what's the difference but plz try it and also let me know Commented Oct 15, 2012 at 7:07

4 Answers 4

2

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

answered Oct 15, 2012 at 7:03
Sign up to request clarification or add additional context in comments.

7 Comments

@PragneshChauhan :) Awesome!!
I tried this; it's not working. this is my current code: jsfiddle.net/MyBZC
also; its a FORM in another bigger FORM, is that an issue?
I see it (and believe it) but with my code (jsfiddle.net/MyBZC), it's not working :( I don't get it at all... it should be working
Lol click on the click me button hope you are clicking the button ? @PoeHaH :))
|
1

add #id like this

var ds= $("#sfn").serializeArray();
alert(ds);

serializeArray() and serialize() both are working for me please check myfiddle

answered Oct 15, 2012 at 6:57

1 Comment

I'm sorry, it was a typo in my code. the # selector is there, but it's not working.
1

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.

answered Oct 15, 2012 at 7:07

2 Comments

@PoeHaH bruv, serialise is working see here: jsfiddle.net/bnTLR my reply above as well :) hope it helps you! Hope you are clicking the button to get the alerts.
yes I am.. I SEE it's working in this code, but whenever I ADAPT my code to this example, it's not working
0

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"

answered Oct 15, 2012 at 7:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.