javascript - Submitting form values to a JS array object rather than to an AJAX request -


been working on issue while , cant head around it. there few similar answers nothing seems tackle exact issue.

so have form. values going numbers. want capture values inside array perform calculations on them before sending seperate ajax call new variables. im surprised @ how hard seems to working.

my code should outputting values of form key/value pairs within array x, array seems empty (contains {object object} pairs every form name/value pair.

any ideas? if there better method achieving this, i'm ears (or eyes, whatever!). guess easy way bind click rather submit event, dont want lose other user form submission abilities (pressing enter etc).

javascript:

$('#zombieform').submit(function(event) {     event.preventdefault()     var x = $(":input").serializearray();     alert(x); //currently using sandbox without console }); 

html:

<form id="zombieform" method="post">     <select name="multi2" required>         <option value=""></option>         <option value="100">placeholder value 4</option>         <option value="50">placeholder value 3</option>         <option value="25">placeholder value 2</option>         <option value="0">placeholder value 1</option>     </select>     <input type="submit" value="submit" id="formbutton" /> </form> 

you this. you're after? fiddle

$('#zombieform').submit(function(event) {     event.preventdefault();     var yourarray = {};     $.each($(this).serializearray(), function() {         yourarray[this.name] = this.value;     });     console.log(yourarray); }); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -