proper syntax to set a textbox to a get value and click a button

I have the following php script:
<?php
include 'Services/Twilio/Capability.php';

$accountSid = 'xxxx';
$authToken  = 'xxxx';

$token = new Services_Twilio_Capability($accountSid, $authToken);
$token->allowClientOutgoing('APe24bb77c150e7028610672ebce5198f2');
$token->allowClientIncoming("SMI");
?>

<!DOCTYPE HTML>
<html>
	<head>
		<title>
			Twilio Client Click to Call
		</title>
		<script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script>
		<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
		<script type="text/javascript">
		$(document).ready(function(){

			Twilio.Device.setup("<?php echo $token->generateToken(86400);?>");
			var connection=null;
			
			$("#tocall").keypress(function(e) {  
				if (e.which == 13) {
					params = { "tocall" : $('#tocall').val()};
					connection = Twilio.Device.connect(params);
				}
			});
			$("#call").click(function() {  
				params = { "tocall" : $('#tocall').val()};
				connection = Twilio.Device.connect(params);
			});
			$("#hangup").click(function() {  
				Twilio.Device.disconnectAll();
			});

			Twilio.Device.ready(function (device) {
				$('#status').text('Ready to start call');
			});

			Twilio.Device.incoming(function (conn) {
				if (confirm('Accept incoming call from ' + conn.parameters.From + '?')){
					connection=conn;
				    conn.accept();
				}
			});

			Twilio.Device.offline(function (device) {
				$('#status').text('Offline');
			});

			Twilio.Device.error(function (error) {
				$('#status').text(error);
			});

			Twilio.Device.connect(function (conn) {
				$('#status').text("Successfully established call");
				toggleCallStatus();
			});

			Twilio.Device.disconnect(function (conn) {
				$('#status').text("Call ended");
				toggleCallStatus();
			});
			
			function toggleCallStatus(){
				$('#call').toggle();
				$('#hangup').toggle();
				$('#dialpad').toggle();
			}

			$.each(['0','1','2','3','4','5','6','7','8','9','star','pound'], function(index, value) { 
		    	$('#button' + value).click(function(){ 
					if(connection) {
						if (value=='star')
							connection.sendDigits('*')
						else if (value=='pound')
							connection.sendDigits('#')
						else
							connection.sendDigits(value)
						return false;
					} 
					});
			});


		});

		</script>
	</head>
	<body>
		<div align="center">
			<br/><br/><br/><br/>Number to call: <input type="text" id="tocall" value="">
			<input type="button" id="call" value="Start Call"/>
			<input type="button" id="hangup" value="Hangup Call" style="display:none;"/>
			<div id="status">
				Offline
			</div>
			<div id="dialpad" style="display:none;">
				<table cellspacing="3">
				<tr>
				<td align="center"><input type="button" value="1" id="button1"><br />&nbsp;</td>
				<td align="center"><input type="button" value="2" id="button2"><br />ABC</td>
				<td align="center"><input type="button" value="3" id="button3"><br />DEF</td>
				</tr>
				<tr>
				<td align="center"><input type="button" value="4" id="button4"><br />GHI</td>
				<td align="center"><input type="button" value="5" id="button5"><br />JKL</td>
				<td align="center"><input type="button" value="6" id="button6"><br />MNO</td>
				</tr>
				<tr>
				<td align="center"><input type="button" value="7" id="button7"><br />PQRS</td>
				<td align="center"><input type="button" value="8" id="button8"><br />TUV</td>
				<td align="center"><input type="button" value="9" id="button9"><br />WXYZ</td>
				</tr>
				<tr>
				<td align="center"><input type="button" value="*" id="buttonstar"></td>
				<td align="center"><input type="button" value="0" id="button0"></td>
				<td align="center"><input type="button" value="#" id="buttonpound"></td>
				</tr>
				</table>
			</div>
		</div>
	</body>
</html>

Open in new window

I would like to fill the textbox with id="tocall" and then click the button with id="call" when I pass the query string ?number=5555555555.  Something like this but I don't know the correct php syntax:
if isset($_GET["number"])
{
   document.getElementById("tocall") = $_GET["number"];
   document.getElementById("call").click;
}

Open in new window

TIA
LVL 39
thenelsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
I think you're mixing up PHP and JavaScript.

PHP is interpreted before showing the page. Once you have the page displayed, it's HTML/CSS/JS. PHP is no longer part of the picture, so $_GET is not available.

HTH,
Dan
0
thenelsonAuthor Commented:
I have used $_GET successfully in php before:
<?php
session_start();

$number = $_GET["number"];
....

Open in new window


But, ok, I tried this as a javascript code:
window.onload=StartFunction()
	{
		if isset($_GET["number"])
		{
		   document.getElementById("tocall") = $_GET["number"];
		   document.getElementById("call").click;
		}
	}

Open in new window

It didn't work. What am I doing wrong?
0
Dan CraciunIT ConsultantCommented:
$_GET is an array, the arguments passed to the page via GET. And it's only available on the server.
Once the page is rendered, transformed into HTML/JS code and sent to the client, you can no longer use php. You would need something like
window.onload=StartFunction()
	{
		   document.getElementById("tocall") = 5;
		   document.getElementById("call").click;
		}
	}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
It's like Dan said, you can't readily mix PHP and jQuery.  These technologies run on different machines.  This article explains the relationship and separation.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

If you're new to PHP and want some good learning resources, this article will be helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
thenelsonAuthor Commented:
ok, I got it:
window.onload=function StartFunction()
	{
		var $_GET = <?php echo json_encode($_GET); ?>;
		if (typeof($_GET["number"]) != "undefined" && $_GET["number"] !== null)
		{
		   document.getElementById("tocall").value = $_GET["number"];
		   document.getElementById("call").click();
		}
	}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.