up vote 0 down vote favorite
share [g+] share [fb]

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

link|improve this question

Are you using jQuery, etc ? – hsz May 9 '11 at 12:41
Is function a javascript or Php? – Ankit May 9 '11 at 12:42
feedback

4 Answers

up vote 0 down vote accepted

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

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

link|improve this answer
This works perfectly, thanks very much :) – Daniel H May 9 '11 at 13:04
feedback

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.

link|improve this answer
feedback

Call that voipCall() in the voiphangup().

link|improve this answer
feedback

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;
link|improve this answer
1  
HTMLElementNodes don't have a val method. – Quentin May 9 '11 at 12:44
Sorry, I was a bit quick there... fixed the error. – Adrian Schmidt May 9 '11 at 12:45
Thanks for your help Adrian, I used Garth's solution in the end but I'll keep a record of yours too – Daniel H May 9 '11 at 13:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.