0

Can I do something like this:

$('#myTag').attr('value').load('my_php_file.php');
2
  • api.jquery.com/load based on this I don't see why not! Commented Jul 20, 2012 at 21:25
  • You can, but not in the way you are doing it. Even so, it would make more sense to do it using $.get or $.ajax since it wouldn't require creating a dummy dom element to temporarily contain the string. Commented Jul 20, 2012 at 21:26

1 Answer 1

4

No, because .attr('value') returns a string (representing the value of the value attribute on the DOM element) and it is pretty meaningless to call the .load() method on a string. You usually call this method on a DOM element. To illustrate your problem, here's what your code is equivalent to:

var value = 'some value';
value.load('my_php_file.php');

Nonesense.

Did you mean:

$.ajax({ 
    url: 'my_php_file.php', 
    success: function(result) { 
        $('#myTag').val(result); 
    } 
});
Sign up to request clarification or add additional context in comments.

5 Comments

What's I'm trying to do is ajax in a value into a tags value attribute.
I don't understand what you are talking about. You mean like the value attribute of this DOM element is pointing to the id of some other DOM element that you want to feed with the results of an AJAX call?
I have an input tag (text field), and I want to change the value inside the text field via ajax.
You mean like $.ajax({ url: 'my_php_file.php', success: function(result) { $('#myTag').val(result); } });?
Yes, I think that's it. I have to leave right now, but I'll try that when I get back. Thanks for the suggestion!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.