Nastya Gorobets
Nastya Gorobets

Reputation: 197

Pass variable in function js

I have code :

<td><input type="hidden" id="someText" name="someText" value="Hello World!">  </td>
<td><button onclick="test(document.getElementById('someText'))">Invoke Some</button></td>

I want to pass someText to my test() . But I get [object HTMLInputElement]. I must pass it in html no in

Upvotes: 0

Views: 31

Answers (2)

Sravan
Sravan

Reputation: 18647

Use the id of the div to get the value in it and pass it to the function.

<input type="hidden" id="someText" name="someText" value="Hello World!">  </td>
<td>
    <button onclick="test(document.getElementById('id of your div').value)">Invoke Some</button>
</td>

Upvotes: 1

gurvinder372
gurvinder372

Reputation: 68373

You are passing the Element Object, you need to access its value

<td><button onclick="test(document.getElementById('someText').value)">Invoke Some</button></td>

Replaced

test(document.getElementById('someText'))

with

test(document.getElementById('someText').value)

Upvotes: 4

Related Questions