Daniel H
Daniel H

Reputation: 2925

Passing HTML input data to Javascript call

I am currently using this code:

<input type=button value='Call' class="call" onClick='voipCall("<?php echo $number_1;?>")'>
<input type=button id="callendbutton" class="hangup" value='Hangup' onClick='voipHangup()'>

which uses the variable $number_1 and passes it into a javascript function to call that number. Now I need another section which lets the user input their own number to call, but I'm not sure how to pass the information from the text input box into the function call.

Something like this:

<input type="text" tip="Enter alternate phone number" name="phonenumber" id="phonenumber" size="40" value=""/>
<input type=button value='Call' class="call" onClick='voipCall("#phonenumber")'>
<input type=button id="callendbutton4" class="hangup" value='Hangup' onClick='voipHangup()'>

Is there an easy way to do this?

Thanks for any help

Upvotes: 0

Views: 966

Answers (4)

PhiLho
PhiLho

Reputation: 41142

Use 'title' instead of 'tip'.
Use document.getElementById('phonenumber') to access the input field and get its value.
You can set a variable with default set by PHP if you want, getting the input field value if non empty, and use this variable in your JavaScript call.

Upvotes: 0

Garth
Garth

Reputation: 1446

You can use javascript to get the text from your phonenumber input text field.

jquery: voipCall($("#phonenumber").val())

Upvotes: 0

X10nD
X10nD

Reputation: 22040

Call that voipCall() in the voiphangup().

Upvotes: 0

Adrian Schmidt
Adrian Schmidt

Reputation: 1885

You can use the id "phonenumber" to fetch the text-input node, and then get the current value from it:

var number = document.getElementById('phonenumber').value;

Upvotes: 2

Related Questions