Saturday, January 12, 2019

hurry jquery to c

HTML: JS: var nameValue = document.getElementById("uniqueID").value; share improve this answer answered Aug 23 '10 at 11:28 user406632 774●7●8 7 @shorty876: Did you test it yourself? o_0 That would be a pretty good way of determining whether or not you did it right. – Jeff Rupert Aug 23 '10 at 11:46 1 Yeah, but it just returns a true/false and im not sure how to determine if the function was even called. Thus you can help. – user377419 Aug 23 '10 at 13:00 I tried this out, but nameValue is the default value and not what the user entered. – James T. Dec 12 '17 at 20:54 add a comment up vote 27 down vote If you want to retrieve the form values (such as those that would be sent using an HTTP POST) you can use JavaScript new FormData(document.querySelector('form')) form-serialize (https://code.google.com/archive/p/form-serialize/) serialize(document.forms[0]); jQuery $("form").serializeArray() share improve this answer answered Dec 21 '16 at 12:33 Kevin Farrugia 2,098●16●29 6 Your first example FormData itself doesn't do anything.. you still need to get the values from the form. – putvande Dec 21 '16 at 12:39 1 I believe that is incorrect. If when initialising the FormData you specify a form element then it will correctly retrieve the values. codepen.io/kevinfarrugia/pen/Wommgd – Kevin Farrugia Dec 21 '16 at 13:34 1 The FormData object is not itself the values though. You still need to call and iterate through FormData.entries() in order to retrieve the values. Additionally, FormData.entries() is not available in Safari, Explorer, or Edge. developer.mozilla.org/en-US/docs/Web/API/FormData – dave Oct 11 '17 at 21:08 Correct in regards to browser compatibility, however there are polyfills. Regarding iterating through formData.entries(), it depends what you are looking for. If you are looking for the value of a single field you could use formData.get(name). Reference: get(). – Kevin Farrugia Oct 12 '17 at 7:02 Yeah I can't get FormData to output anything on Chrome. – Atav32 Mar 26 '18 at 19:11 show 1 more comment up vote 22 down vote document.forms will contain an array of forms on your page. You can loop through these forms to find the specific form you desire. var form = false; var length = document.forms.length; for(var i = 0; i < length; i++) { if(form.id == "wanted_id") { form = document.forms[i]; } } Each form has an elements array which you can then loop through to find the data that you want. You should also be able to access them by name var wanted_value = form.someFieldName.value; jsFunction(wanted_value); share improve this answer answered Aug 23 '10 at 11:35 Codeacula 1,549●15●24 edited Mar 14 '15 at 23:20 up vote 15 down vote Here is an example from W3Schools : function myFunction() { var elements = document.getElementById("myForm").elements; var obj ={}; for(var i = 0 ; i < elements.length ; i++){ var item = elements.item(i); obj[item.name] = item.value; } document.getElementById("demo").innerHTML = JSON.stringify(obj); } The demo can be found here. share improve this answer answered Aug 7 '16 at 5:20 Tran Nguyen Nhat Thuy 151●1●3 edited Aug 7 '16 at 5:55 Menasheh 1,540●1●19●33 7 Just a warning, if anyone wants to get the selected values of other types of inputs such as radio buttons or checkboxes, this won't do what you want. – Sean Nov 23 '16 at 5:59 add a comment up vote 1 down vote let value = document.getElementById("note_text").value; share improve this answer answered Dec 13 '17 at 4:59 Randhawa 185●14 up vote 0 down vote Several easy-to-use form serializers with good documentation. In order of Github stars, jquery.serializeJSON jquery-serialize-object form2js form-serialize

No comments:

Post a Comment