php - Passing Input field type along with the value using json -


i want pass input field type along value of input field. far i'm successful in getting value of input field adddata.php. cant find way input field type. please help. code.

<html lang="en"> <head>     <meta charset="utf-8">     <title>attr demo</title>      <script src="jquery.js"></script> </head> <body>     <form action="adddata.php">     <input id="name" type="text" name="name">     <button id="submit">submit</button>     </form>  <script>     $(document).ready(function() {              $('#submit').click(function(){            $.ajax({                type        : 'post',                url         : 'adddata.php',                data        : {name:$('#name').val(),type:$('input').attr("type")},                datatype    : 'json',                encode          : true                success:function(jsondata){                    alert('success!');                }             });        });     }); </script> </body> </html> 

and adddata.php file

<?php    $name = $_request['name'];    $type = $_post['type'];     echo $name;    echo $type; ?> 

your don't need ajax call since submitting form - remove script , replace with:

$('form').submit(function() {     // before submit     $(this).prepend(      '<input type="hidden" name="type" value="'+$('input').attr('type')+'" />'     );     return true; // return false cancel form action }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -