$(function() {
$.get('http://localhost/rand.php', function(data){
document.getElementsByName('login')[0].value='data';
console.log(data);
});
});
what is the problem in these code. they are giving me error like "background.js:3 Uncaught TypeError: Cannot set property 'value' of undefined".
$(function() {
$.get('http://localhost/rand.php', function(data){
document.getElementsByName('login')[0].value='data';
console.log(data);
});
});
what is the problem in these code. they are giving me error like "background.js:3 Uncaught TypeError: Cannot set property 'value' of undefined".
Share Improve this question edited Dec 26, 2015 at 17:29 jianweichuah 1,4171 gold badge11 silver badges22 bronze badges asked Dec 26, 2015 at 8:39 aarif khanaarif khan 211 silver badge2 bronze badges 1-
You could try
document.getElementsByTagName('input')...
– Bahramdun Adil Commented Dec 26, 2015 at 8:42
1 Answer
Reset to default 3Do you have name=login
element in your HTML
page, if no then you cannot get the element and its value.
You can have something like this:
<input type="text" name="login" value="OK">
Then you can get this element by name and then get the value.
Below is what I tried:
function onLoad() {
var value= document.getElementsByName('login')[0].value;
alert("value="+value); // value=OK
}