0

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');
        }

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Hope this pluker will help

Plunker

Code is

function clDoc() {
            path = document.getElementById('clDoc').value;
            alert(path);
            var myWindow = window.open(path, '', 'width=520,height=650');
        }

1 Comment

Yep, wrong ID was used for document.getElementByID().

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.