jQuery value of field not defined -
I have a very basic form with a selected field, which can have several options.
To submit my form, I check the length and if there is at least one value then I generate an XML string for each of them.
var type = $ ('[name = advancedType]') .val (), newType = type.split (','), type XML; If (newType.length & gt; 0) {typeXML = '& lt; Type & gt; '; (Var i = 0; i & lt; newType.length; i ++) {typeXML + = '& lt; Type & gt; '; TypeXML + = '& lt; TypeID & gt; + New type [i] + '& lt; / TypeID & gt; '; TypeXML + = '& lt; / Type & gt; '; } Type XML + = '& lt; / Types & gt; '; } Else {typeXML = ''; }
When choosing an option, it works fine, but when I do not choose anything, it says that the type is not defined.
How can I get it to work as a purpose? Looks very simple ..
var newType = (type & amp; amp; And; ',')) || [];
Comments
Post a Comment