[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-03-04
5
Medium Priority
?
490 Views
Last Modified: 2014-03-04
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
0
Comment
Question by:thenelson
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39903178
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
 
LVL 39

Author Comment

by:thenelson
ID: 39903273
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
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 1500 total points
ID: 39903328
$_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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39903334
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
 
LVL 39

Author Comment

by:thenelson
ID: 39903343
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question