php - Add two variables values in one variable with if else condition when data pass through ajax -
i want add 2 variables(class textbox , hiddentxtbox) values in 1 variable(check) using if else condition , want pass 1 variable(check)in ajax.i want if select database headers options firstname,lastname dropdown value pass through checkbox else textbox value pass through checkbox.in script have pass check variable this:- data: { check: textbox, oldval: textbox1,hiddentxtbox:hiddentxtbox,olddropval:textbox2} in above code check variable has 1 value textbox.i want if select database headers options firstname,lastname dropdown value pass through checkbox check:hiddentxtbox else check:textbox
<script> $(document).ready(function(){ $('#submit').click(function(){ var hiddentxtbox=[]; var textbox = []; var textbox1 = []; var textbox2= []; var check = []; $('.check').each(function() { if ($(this).is(':checked')) { var current = $(this).val(); //alert(current); textbox.push($(this).parents("tr").find(".textbox").val()) textbox1.push($(this).parents("tr").find(".textbox1").val()) textbox2.push($(this).parents("tr").find(".textbox2").val()) hiddentxtbox.push($(this).parents("tr").find(".newhiddenbox").val()) } check.push($(this).val()); }); $.ajax({ url: 'practice.php', type: 'post', data: {check: textbox, oldval: textbox1, hiddentxtbox: hiddentxtbox, olddropval: textbox2}, success: function (data) { alert(data); } }); return false; }); }); </script> <table> <tr> <td> <select name='drop[]' class='select_drop textbox textbox1 form-control'> <option value="firstname">firstname</option> <optgroup label='newtextfields' class='txtfields' > <option value='text' >text</option> <option value='number'>number</option> </optgroup> <optgroup label='database headers'> <option value="firstname">firstname</option> <option value="lastname">lastname</option> <option value="email">email</option> } </optgroup> </td> <td><input type='hidden' value='firstname' class='textbox2 form-control' id='textbox2'></td> <td><input type='hidden' id='newhiddenbox' class='newhiddenbox' value='firstname'></td> <td><input type='checkbox' name='check' value='firstname' class='check checkbox-primary' >add column</td> <br> </select> </tr> </table> </div> <div class='form-group'> <table> <tr> <td> <select name='drop[]' class='drop form-control' > <optgroup selected label='newtextfields'> <option value='text'>text</option> <option value='number'>number</option> </optgroup> <optgroup label='database headers' class='hd'> <option value="firstname">firstname</option> <option value="lastname">lastname</option> <option value="email">email</option> </optgroup> </select> </td> <td><input type='text' value='lastname' class='textbox tt form-control' id='textbox'></td> <td><input type='hidden' value='lastname' class='textbox1 form-control' id='textbox1'></td> <td><input type='hidden' id='newhiddenbox'class='newhiddenbox' value='lastname'></td> <td><input type='checkbox' name='check' value='lastname' class='check checkbox-primary' style='margin-left:5px;'>add column</td> </tr> </table> </div> </div> </div> <input type='submit' name='submit' id='submit' value='submit' > </div>
Comments
Post a Comment