Reputation: 1078
I am getting text-box value in JavaScript. My text-box value is "xxxxx?000-1111". While I am trying to get this value from JavaScript function I am getting the value as [object%20HTMLDivElement].... can anyone tell me, What is the mistake I have made here.
Textbox and button, text box value is replaced from other method and shows well in page.
function clDoc() {
path = document.getElementById('val').value;
alert(path);
var myWindow = window.open(path, '', 'width=520,height=650');
}
<input type="text" id="clDoc" name="myn" value="" />
<input type="button" onClick="clDoc()" value="View" id="groupbtn" />
Javascript
function clDoc() {
path = document.getElementById('val');
alert(path);
var myWindow = window.open(path, '', 'width=520,height=650');
}
If I tried with following I am getting alert as undefined.
function clDoc() {
path = document.getElementById('val').value;
alert(path);
var myWindow = window.open(path, '', 'width=520,height=650');
}
Upvotes: 0
Views: 115
Reputation: 2871
Hope this pluker will help
Code is
function clDoc() {
path = document.getElementById('clDoc').value;
alert(path);
var myWindow = window.open(path, '', 'width=520,height=650');
}
Upvotes: 1
Reputation: 944524
Compare:
path = document.getElementById('val').value;
where you get the value from the HTML Element Object and
path = document.getElementById('val');
where you get the HTML Element Object itself.
path = document.getElementById('val').value;
Now, you are getting the value property but you said that it was:
[object HTMLDivElement]
Div elements are not text inputs. They are not user editable and don't have values.
Maybe you want to get the innerHTML
instead.
Upvotes: 6