Get all form values in javascript and send the values back to php page -
i'm using ajax way process data have lot of forms , , did check of forms values using jquery , i'm ok values types , of validation staff .. i'm wondering how values " i'm talking 25 input ,, , send php page
example :
<input type="text" name="emp_user_name" id="emp_user_name" placeholder="user name" /></li> <li><input type="password" name="pass" id="pass" /></li> <li><input type="password" name="pass2" id="pass2" /></li> <li><input type="text" name="emp_group" id="emp_gorup" placeholder="group" /></li> <li><input type="text" name="emp_ar_name" id="emp_ar_name" placeholder="employee name" /></li> <li><input type="text" id="emp_en_name" style="direction:ltr!important;" id="emp_en_name" placeholder="full name" style="direction:ltr ;" /></li> <li><input type="text" id="emp_address" name="emp_address" placeholder="address" /></li> <li><input type="text" name="emp_num1" style="direction:ltr!important;" id="emp_num1" placeholder="091" /></li> <li><input type="text" name="emp_num2" style="direction:ltr!important;" id="emp_num2" placeholder="092" /></li> <li><input type="text" name="emp_email" style="direction:ltr!important;" id="emp_email" placeholder="support@huemix.ly" /></li> <li style="padding: 39px;">male : <input type="radio" name="emp_sex" id="emp_sex" placeholder="male" /> female : <input type="radio" name="emp_sex" id="emp_sex2" placeholder="female" /> </li> <li><input type="text" name="emp_bday" id="emp_bday" placeholder="17/02/2011" /></li> <li><input type="submit" name="save" onclick="add_emps_to_db()" id="save" value="" /></li> this 1 of forms .. , javascript function
function add_emps_to_db(){ nocashe = math.random(); http.open('get','huemix_custom.php?section=emps&action=add_new_emps_to_db&" wanna data here"&nocache = '+nocache); http.onreadystatechange = huemixinsertreplay; http.send(null); }
i using way , it's not flexible way work lot of forms
var first_name= encodeuri(document.getelementbyid('first_name').value); var middle_name= encodeuri(document.getelementbyid('middle_name').value); var last_name= encodeuri(document.getelementbyid('last_name').value); var phone_num1= encodeuri(document.getelementbyid('phone_num1').value); var phone_num2= encodeuri(document.getelementbyid('phone_num2').value); var work_type= encodeuri(document.getelementbyid('work_type').value); var work_place= encodeuri(document.getelementbyid('work_place').value); var from= encodeuri(document.getelementbyid('from').value); var worktype1 = $("#worktype1").is(':checked')?1:0; var worktype2 = $("#worktype2").is(':checked')?1:0; var worktype3 = $("#worktype3").is(':checked')?1:0; var site_name= encodeuri(document.getelementbyid('site_name').value); var start_date= encodeuri(document.getelementbyid('start_date').value); var end_date= encodeuri(document.getelementbyid('end_date').value); var site_url= encodeuri(document.getelementbyid('site_url').value); var script_type= encodeuri(document.getelementbyid('script_type').value); var last_mod= encodeuri(document.getelementbyid('last_mod').value); var cpanel_url= encodeuri(document.getelementbyid('cpanel_url').value); var cpanel_user= encodeuri(document.getelementbyid('cpanel_user').value); var cpanel_pass= encodeuri(document.getelementbyid('cpanel_pass').value); var adminpanel_url= encodeuri(document.getelementbyid('adminpanel_url').value); var adminpanel_user= encodeuri(document.getelementbyid('adminpanel_user').value); var adminpanel_pass= encodeuri(document.getelementbyid('adminpanel_pass').value); var other_url= encodeuri(document.getelementbyid('other_url').value); var other_user= encodeuri(document.getelementbyid('other_user').value); var other_pass= encodeuri(document.getelementbyid('other_pass').value); var ftp_url= encodeuri(document.getelementbyid('ftp_url').value); var ftp_user= encodeuri(document.getelementbyid('ftp_user').value); var ftp_pass= encodeuri(document.getelementbyid('ftp_pass').value); var support= $("#support").is(':checked')?1:0; var support_end_date= encodeuri(document.getelementbyid('support_end_date').value); var id= $(this).closest("td").find("#huemix_id").value; var notes = encodeuri(document.getelementbyid('notes').value); i wanna foreach loop example .. or way add input field id + input field value ,, , add of link automatic ,,
example : wanna link
huemix_custom.php?section=emps&action=add_new_emps_to_db&id_for_virst_input=value_for_first_input&id_for_second_input=value_for_second_input... , goes on way&nocache = '+nocache note : see have 3 types , input type text , password , radio
thanx way
i use code reading form values dictionary:
function getformvalues(form) { var res = {}; var elems = getelementsbytagandclassname(null, null, form); (var = elems.length - 1; >= 0; i--) { var elm = elems[i]; var nodename = elm.nodename.tolowercase(); var type = elm.type; if (!type) type = ""; type = type.tolowercase(); if ((nodename == "input" || nodename == "select") && elm.name) { var checked = true; if (type == "checkbox" || type == "radio") { checked = elm.checked; } if (checked) { res[elm.name] = elm.value; } } } return res; } the function getelementsbytagandclassname mochikit, there other implementations out there. function returns list of domnodes children of form. can iterate on them using firstchild/nextchild or other access method
Comments
Post a Comment