Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to get value of hidden element named "login" on http://ts1.travian.ro/'s login page, in order to create a fake login for my Chrome extension.

I would like to do it without jQuery if possible. If not here is my not working example:

var url = 'http://ts1.travian.ro/';

$.ajax({
    type: "GET",
    dataType: 'html',
    url: url,
    success: function(data) {
        loginValue = $(data).find('input[name=login]').html();
        console.log(loginValue);
    },
});

I expected to see the login name in the console, but nothing appeared. How can I solve it?

share|improve this question
And what happens then.? Are you getting any errors – User016 Jul 14 at 11:38
Didn`t get any value .. – smotru Jul 14 at 11:41

2 Answers

up vote 1 down vote accepted

Try with $("element").val() method.

var url = 'http://ts1.travian.ro/';

$.ajax({
    type: "GET",
    dataType: 'html',
    url: url,
    success: function(data) {
        loginValue = $(data).find('input[name=login]').val();
        console.log(loginValue);
    },
});
share|improve this answer
thank you, it worked – smotru Jul 14 at 11:46
Welcome @smotru. Plz mark it as correct answer.. – User016 Jul 14 at 11:47
i will mark it in 2 minutes – smotru Jul 14 at 11:48

The html() method (which wraps the innerHTML DOM property) returns the HTML source for the elements inside the current element.
<input> cannot have children, so this always returns an empty string.

You want .val() (which wraps the value DOM property), which returns the current value of an input element.

share|improve this answer
I have tried with .val() but returned null – smotru Jul 14 at 11:42
@smotru: There is no value() function. jQuery has a function called val; native DOM objects have a property called value. You need to learn the DOM. – SLaks Jul 14 at 11:44
thank you, it worked.. – smotru Jul 14 at 11:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.