Search code examples
phpjqueryajaxgetslug

jquery.get result from php to another input


I'm using the following code:

$('#inputname').change(function(){ //on change event
            var parentVal = $('#inputname').val(); 
            $.ajax({
                url     : 'file.php',
                type    : 'GET', //type of request, GET or POST
                data: ({ svalue: parentVal }),
                success : function(data){ $('#slug').html(data); }
            });

        });

I want to display what is being typed in one text field to another text field, after processing it in php. In file php I only have an echo $_GET['svalue'] for test purpose.

Any thoughts? Thank you!


Solution

  • If it's a text field, use .val instead of .html

     $('#slug').val(data);