Solved

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

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 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