Solved

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

Posted on 2014-03-04
5
478 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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 110

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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