Solved

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

Posted on 2014-03-04
5
469 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 34

Expert Comment

by:Dan Craciun
Comment Utility
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
Comment Utility
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 34

Accepted Solution

by:
Dan Craciun earned 500 total points
Comment Utility
$_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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now