Question

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!

Était-ce utile?

La solution

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

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

Autres conseils

I have something to share that may help you. Where to use:

use .html() to operate on containers having html elements.
use .text() to modify text of elements usually having separate open and closing 
            tags

Where not to use:

.text() method cannot be used on form inputs or scripts.
    .val() for input or textarea elements.
    .html() for value of a script element.

Picking up html content from .text() will convert the html tags into html 
entities.

Difference:

.text() can be used in both XML and HTML documents.
.html() is only for html documents.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top