I was wondering how to take a value from a ajax call and change the value of a textfield to that value.
I have the following call which grabs the users id and displays an alert box with that value, instead of displaying an alert box, i would like to change the value of a textbox to display that value in it .. any help would be grand.
<script type="text/javascript" charset="utf-8">
$('#users').live('change', function(){
$.ajax({
type: "POST",
url: "returndata",
data: {id: $(':selected', this).val()},
dataType: 'json',
success: function(data){
alert(data.id);
}
});
});
</script>
Just change your
successfunction to alter the value of the textfield instead of performing the alertSuppose the textfield in question has
id="textFieldId"You can probably simplify this, if you care to, with
$.load()instead of$.ajax(). http://api.jquery.com/load/