Jump to content

Search the Community

Showing results for tags 'javascript'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

  1. Hi everyone. I'm trying to write a cookie for a site I'm working on the displays a page until it triggers an onclick event. I have a section of the site that pulls up a disclaimer page with 2 options one that says I disagree and shoots you to the home page and one that triggers the cookie which if it's started in your browser will redirect you to the section you need to agree to in order to see. I've been able to get it to work upon visit, but I'm not having any luck with the on click event. I've been tweaking the script I found here --> http://www.javascrip...redirect-2.html I feel like I'm pretty close and have tried many onclick variations the following code I think is close. <a href="after-disclaimer-page.com" onClick="SetCookie('HasVisited')">I AGREE</a> Anyone have any ideas?
  2. Hello. I am building a page for people with disabilities that involves demonstrating several fonts. There will be a pane with buttons that either a) call different classes that will load the environment, or call the jquery .css() function to load the environment that way. I have gotten both methods to work--for everything except the font-family. I've put the font-stacks into the classes, loaded the classes, and everything but font-family works. I've also loaded everything into a .css() statement--and everything but font-family works. Here's the jQuery I'm using now: <code> $(document).ready(function(){$("#numone").click(function(){ $("#texdiv").toggleClass("graybkd"); $("#texdiv").html("Here the text is blue on a Gray Background. Does this feel better? This font should be Arial, which is easier for vision-impaired people to read..."); }); }); </code> When I do everything with the .css(), the toggleClass statement is commented out and after the event handler the code looks like this: <code>$("#texdiv").css({"font-family" : "Verdana", "background-color" : "#dddddd", "border-color" : "#0000dd"}); --- etc. </code> If you want to see how this all works, you can check the following jsfiddle.net page:http://jsfiddle.net/gershonb/eJapD/118/ As you will see, everything works--except the font-family change. It kind of stumps me when everything works except for one small part. Thanks Gershon
  3. Can someone please give me some example code so I can link a webpage to another using javascript? This is my code at the moment:- document.onkeydown = function(e) { e = e || window.event; // because of Internet Explorer k = e.which || e.charCode || e.keyCode; // because of browser differences... if (k == 49 && !e.altKey && !e.ctrlKey && !e.shiftKey) { string.link(link.html) } else { return true; } return false; } This won't link me to the other link when "1" on the keyboard is pressed... Please Help!
  4. Hello all,I have tried so many things to get this to work but to no avail, can someon eplease help me out here with a simple script for n XML steam feed.http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=221380&format=xml OK NOW THE ISSUE IS:I have a blank webpage which I have placed the above link into, I simply want the contents of the XML feed from the link to appear in mypage.......How do I make the contents of that url appear on the same page??SO I NEED THE SMALL SCRIPT OR HTML CODE TO DO THISAlso I would like to have the background a certain colour and use a certain font like 12point arial with bold headings and lower case text.Can someone please provide me with the html to allow this XML feed to appear on my webpage with a different colour background, arial 12pt font inbold and lowercase____________________________________________________________________________I RECEIVED A REPLY TO THIS POST AND THEY ADDED THIS:It's a little hard to tell from what you wrote. But, I think what you are looking for is an AJAX script to pull in the XML,then CSS can take care of the formatting.Look up how to process a XMLHttpRequest in javascript (or another scripting language). That will let you put the XML file into an array. Then,you can use (javascript) document.write() to put the pieces on your page.______________________________________________________________________________SO this being said do I need a javascript code in the page to show the XML Feed with formatting, what would this code be, this is the magicalquestion :)Could someone please please help me..........With regardsMathew
  5. Would someone be able to comment this JavaScript for me to help give me a better understand of what the actual code is doing (I am still a learner) Thanks <script type="text/javascript"><!--function rotator(options) {var a = options.delay;var b = options.media;var mediaArr = []; for(var i = 0, j = b.length; i < j; i++) { mediaArr.push(b[i].img);} document.write('<div id="rotatorContainer"></div>');var container = document.getElementById('rotatorContainer');var Start = 0; rotatorCore(); function rotatorCore() {Start = Start + 1; if(Start >= mediaArr.length)Start = 0;container.innerHTML = mediaArr[Start];//console.log(Start);setTimeout(rotatorCore, a); } } rotator({delay : 2500, media : [{img : '<img src="Example.jpg" width="212" height="300" border="0" />'}]});// --></script>
  6. Hello internet Safari is not allowing my radio buttons to work and it will not let submit my form connected with those... any help is greatly appreciated. Thanks. SUBMITTING THE FORMHTML<form name=poll1 id=poll1 method="post" target="_blank">.....<input type="radio" name="ne" id="ne1" value="1">.....</form> JAVAfunction poll1submit(){poll1.action = "polls_p.php";document.getElementById('poll1').submit()}
  7. Would someone be able to give me examples on how JavaScript is implemented in different browsers. Thanks
  8. I'm trying to learn Javascript and I've just briefly read about recursion in functions. I've been given the following task. Consider this puzzle: By starting from the number 1 and repeatedly adding 5 or multiplying by 3, an infinite amount of new numbers can be produced. How would you write a function that, given a number, tries to find a sequence of additions and multiplications that produce that number? For example, the number 13 could be reached by first multiplying 1 by 3, and then adding 5 twice. The number 15 can not be reached at all. Here is the solution: function findSequence(goal) { function find(start, history) { if (start == goal) return history; else if (start > goal) return null; else return find(start + 5, "(" + history + " + 5)") || find(start * 3, "(" + history + " * 3)"); } return find(1, "1");} print(findSequence(24)); If this code is run the following is printed to the console: (((1 * 3) + 5) * 3) In my head, the code is processed in the following steps. 1. findSequence is called, with a parameter value of 24.2. findSequence calls find giving the first parameter a value of 1 and the second parameter a value of "1".3. The find function looks to see if the start parameter value is equal to the value of the goal parameter.4. As the start parameter value, in this particular case, is not equal to the value of the goal parameter, check to see if the start parameter value is larger than the goal parameter value.5. As the start parameter value, in this particular case, is not equal to the value of the goal parameter, return one of the following statements:find(start + 5, "(" + history " + 5)")orfind(start * 3, "(" + history + " * 3)" However, this is then where I become stuck. I can't quite understand the statements it's trying to then run. I can see that find(start + 5, changes the value of history to 5. Then "(" + history + " + 5)") . This to me would print (1 + 5 ( + 5) + 5)). Similarly I see the other statment printing as (1 * 3 ( + 3) * 3)). I just can't quite grasp what I'm missing. I suspect it's something obvious and really simple but it would be great if someone could provide me with the missing pieces. I appreciate that there is most likely an alternative way of coming to the same result. However, I'd like to fully understand what is being shown to me here before I move on. Many thanks.
  9. http://goo.gl/H5mSy <- heres an example of what i want . If you notice when you hover the border slides from the left , is it possible to do this with css or javascript is needed? I found something like this so far but its not exactly the same .. http://jsfiddle.net/skram/dEK9A/4/
  10. Do you have to Re-Declare a variable to assign it a different Data Type?
  11. Hello. I am doing a tutorial on youtube, and a guy (teacher, i am not sure if I can advertise him here) is showing a lesson - "Calling function from another function" on a video, he is writing and generating the code to the web page, but I write the same code - nothing happens. My code is: <html><head><title>Tutorial</title><script type="text/javascript">function doFirst() { document.write("one two three"); }function doSecond() { document.write("My name is Juris"); }function start() { function doFirst(); function doSecond(); } start();</script></head><body></body></html> - it is very basic, but it is not popping on my screen. I do not understand why? I have checked everything for mistakes. Does somebody know the answer?
  12. Hi, I'm trying to create a navigation menu. When you click on each item of the menu, it displays the corresponding target page below and hides the others. You will find HTML & JS code below and in attachment. Here is the way I proceed: with JS and my "initiateNavigation" function, I :1) attach a JS function to every link of the menu. This "navigation" function will be called on click and hide all the pages and display only the selected one.2) call the navigation function to display the first page (page 1). The initiateNavigation function is called when the document is ready: $(document).ready(function(){}; The problem is that every time I click on a link, it does the work and loads the targeted page, but the browser considers the document to be ready again, and it calls the initiateNavigation again and displays page 1. How can I call the initiateNavigation function once only? Thanks, M. HTML code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <title></title> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <script src="http://code.jquery.com/jquery-latest.js"></script> <script src="javascript.js"></script> </head><body> <div> <div id="lienpage1"><a href="">Page 1</a></div> <div id="lienpage2"><a href="">Page 2</a></div> <div id="lienpage3"><a href="">Page 3</a></div> </div> <div> <div id="page1">bla bla page 1</div> <div id="page2">bla bla page 2</div> <div id="page3">bla bla page 3</div> </div> <div>test</div></body></html> JS code: function navigation(destinationsIdsArray,focus){ $.each(destinationsIdsArray, function(){ $('#'+this).hide(); }); $('#'+focus).fadeIn(500); } function initiateNavigation(selectorsIdsArray,destinationsIdsArray){ //selectorsIdsArray = array of ids of the selectors, i.e. divisions containing the links that will be used for selecting the target divisions to focus on. //destinationsIdsArray = array of ids of the target divisions. if(selectorsIdsArray.length!=destinationsIdsArray.length){ alert('both arrays do not have the same length'); return; } $.each(destinationsIdsArray, function(){ $('#'+this).hide(); }); $.each(selectorsIdsArray, function(){ var destination=destinationsIdsArray[$.inArray(String(this),selectorsIdsArray)]; $('#'+this).click(function(){ navigation(destinationsIdsArray,destination); }); }); navigation(destinationsIdsArray,destinationsIdsArray[0]); } $(document).ready(function(){ initiateNavigation(['lienpage1','lienpage2','lienpage3'],['page1','page2','page3']); }); Thanks index.html javascript.js.zip
  13. Would someone be able to comment this JavaScript clock for me please, thanks. <script>function show2(){if (!document.all&&!document.getElementById)returnthelement=document.getElementById? document.getElementById("tick2"): document.all.tick2var Digital=new Date()var hours=Digital.getHours()var minutes=Digital.getMinutes()var seconds=Digital.getSeconds()var dn="PM"if (hours<12)dn="AM"if (hours>12)hours=hours-12if (hours==0)hours=12if (minutes<=9)minutes="0"+minutesif (seconds<=9)seconds="0"+secondsvar ctime=hours+":"+minutes+":"+seconds+" "+dnthelement.innerHTML="<b style='font-size:14;color:black;'>"+ctime+"</b>"setTimeout("show2()",1000)}window.onload=show2//--></script>
  14. Hello internet, I have created a webpage that has to load quite a few elements before it will display. How do I keep the site from showing the individual elements being loaded, just show an initial progress bar when then go to my site, and finally once the progress bar is complete show my full site? Your recommendations on where to start would be great!
  15. Hello internet. I am using the following code and I have not been able to write in a stop function. Nothing I have tried works. Please help. HTML<div class="slides"><img src="photo1.jpg" name="slide" width="180" height="180" /><script type="text/javascript">slideit()</script></div></div> JAVASCRIPTvar image1=new Image()image1.src="photo1.jpg"var image2=new Image()image2.src="photo2.jpg"var image3=new Image()image3.src="photo1.jpg"var step=1function slideit(){if (!document.images)returndocument.images.slide.src=eval("image"+step+".src")if (step<3)step++elsestep=1setTimeout("slideit()",2500)}
  16. Hey Everyone! i am writing a code in which i am creating multiple <li> and i have given every <li> a different href. When i am running it and when i click on the href it is add the link in the current URL. Like this... <li><a href="promotiondetails.html?id=' + employee.id + '">Some Data</a></li> The current URL is like.. http://localhost/mano/www/promotions.html and this happens when i click on the <li>... http://localhost/mano/www/promotions.html#/mano/www/promotiondetails.html?id=275 I don't know whats going wrong. Please help me....
  17. Hi, I'm trying to extract some specific elements (tags) from an XML document which is the result of an ajax query.However, I cannot get any element. Below the alert function displays '0', while the XML document does have 3 'myTag' tags... Any help would be much appreciated Thanks, M. var result = $.ajax({ url: 'server.php', dataType: 'XML', async: false }); var myArray = $(result.responseXML).find('myTag'); alert(myArray.length);
  18. Hi all friendsI have a problem I want to put in highcharts category and is dynamicallyI have an array with names like the Aryeh Data1 defines the category to dynamically put in highchartsI put my codeThank you WebApplication2.zip
  19. What is string?What is parameter?What is parentheses () ? Please see the following codes: <html><head><script type="text/javascript">function show_prompt(){var name=prompt("Please enter your name","Harry Potter");if (name!=null && name!="") { document.write("Hello " + name + "! How are you today?"); }}</script></head><body> <input type="button" onClick="show_prompt()" value="Show a prompt box" /> </body></html> name!=null && name!="" is included here.Here what is the meaning of null?Here what is the meaning of “”? Thank you.
  20. Hello, im wondering how to make select option list with vertical scrollbar like in jquery-ui.http://jqueryui.com/autocomplete/#combobox I wouldn't require that much functions. Just the simple combobox on left side.
  21. I have a div that contains an image. I would like the image to change, approximately every 5 seconds, to another image. There may be up to 10 images that I would like to have rotate (although I suppose the amount of images is, perhaps, irrelevant). I know that this is possible with Java Script. I've seen it work and suspect it's actually fairly straight forward (I'm sure there's countless tutorials on the internet, if I really get stuck). What I'd really like to know is if this is possible without using Java Script and instead using CSS? I believe it's possible in CSS3, as I read an article earlier with someone suggesting it was possible (but their demos weren't working in Internet Explorer). But that is, of course, a problem. I'd like a solution that I can use in most "major" browsers (IE, Chrome, Firefox, Safari etc.). CSS3 is only supported on the latest browsers and, even then, not all features are compatible. So, I don't think that's the answer. Does that leave me with no choice but to use Java Script?
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Join</title></head><body><div id=maincontainer><div id="head"></div><p id="usertxt"> Please to join click on one of the accounts that fits your proffesion.</p><div id="fatline"></div><div id="ceo" onmouseout="offbckg()" onmouseover="showbckg()" onclick="ceoform()"><p id="ceo_txt">C.E.O</p></div> <div id="staff" onmouseout="offbckg()" onmouseover="showbckg()" onclick="staffform()"><p id="staff_txt">Staff</p></div> <div id="student" onmouseout="offbckg()" onmouseover="showbckg()" onclick="ceoform()"><p id="student_txt">Student</p></div> <div id="infobox"><p id="ceoacc">C.E.O Account</p><p id="ceoinfo">The C.E.O account is an account that deals with people who have large business with branches nationwide or worldwide and are employers of Job/labour,and also who have large number of staff 100 and above.This account helps to link them to their staff,customers,business-partners,goverment-officials/organization that the C.E.O does business with.</p><p id="ceoacc">Staff Account</p><p id="ceoinfo">The Staff account is an account that deals with people who are employees in firm/establishments/organizations in various works of life.This account helps to link to their c.e.o,managers and other staff in their organization both national and international.other of the staff-self products can be sold here and more.</p><p id="ceoacc">Student Account</p><p id="ceoinfo">The Student account is an account that deals with people who are (18) years of age and are in a collegde/university (tetary instituation) who after school will become job-seekers,This platform help them to submit their credentials and and let Jobpal search help them do the search for their dream jobs.with Jobpal's platform they can also be Jobpal-lancers(Free-lancers).</p></div> <style type="text/css">#ceoinfo{color:#3CB3C3;font-size:25px;margin:5px;background-color:#e7f2f4;}#ceoacc{font-size:20px;background-color:#3CB3C3;text-align:center;color:white;font-family:"Lucida Console", Monaco, monospace;}#infobox{width:28cm;height:14cm;border:thin solid #3CB3C3;margin-top:-14.1cm;margin-left:6.5cm;}#fatline{width:0.5cm;height:20cm;border:thin solid #3CB3C3;margin-top:-0.7cm;margin-left:3px;background-color:#e7f2f4;}#usertxt{color:#3CB3C3;font-size:24px;font-family:Verdana, Geneva, sans-serif;text-decoration:underline;margin-left:10cm;}*{margin:0cm;}#head{width:auto;height:2cm;background-color:#3CB3C3;}#ceo,#staff,#student{width:5cm;height:2cm;background-color:#e7f2f4;border:thin solid #3CB3C3;margin-left:0.6cm;}#ceo{margin-top:-18cm;} #ceo:hover{border-left-width:0.5cm;border-left-color:#3CB3C3;} #staff{margin-top:4cm;} #staff:hover{border-left-width:0.5cm;border-left-color:#3CB3C3;}#student{margin-top:4cm;} #student:hover{border-left-width:0.5cm;border-left-color:#3CB3C3;} #ceo_txt,#staff_txt,#student_txt{font-size:30px;font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;color:#3CB3C3;text-align:center;margin-top:15px; } </style><script type="text/javascript">function showbckg(){var longline=document.getElementById("fatline").style;longline.backgroundColor="#3CB3C3"; }function offbckg(){var longline=document.getElementById("fatline").style;longline.backgroundColor="#e7f2f4"; }function ceoform(x,y){var delete_infobox=document.getElementById('infobox');var refstudent=document.getElementById('student');} </script></div></body></html>hello fellow web developers please i am writing my webapp but i have issues on this on my join page{register page} in the javascript section of the page i am actually using the DOM to remove the #infobox[div]element....now what i want to do is that i want a sitituation where by where my users click on the the three links the #infobox(id)and all its element are remove and replace with a set of div that is a form which the user will input their registration information in which i will ask them....now these i plan it to go... from the elements.............<div id="fatline"></div><div id="ceo" onmouseout="offbckg()" onmouseover="showbckg()" onclick="ceoform()"><p id="ceo_txt">C.E.O</p></div> <div id="staff" onmouseout="offbckg()" onmouseover="showbckg()" onclick="ceoform()"><p id="staff_txt">Staff</p></div> <div id="student" onmouseout="offbckg()" onmouseover="showbckg()" onclick="ceoform()"><p id="student_txt">Student</p></div>***********************************************************************************************the javascript section of the code...function ceoform(x,y){var delete_infobox=document.getElementById('infobox');var refstudent=document.getElementById('student');delete_infobox.parentNode.removeChild(delete_infobox);}but the problem is that after the elements in the #infobox are deleted.i try to use the document.createElement() function to add a new set of div element after the the info-box have been deleted but the new element are not showing in the browser is it that there some kind of control stucture i will use to create new element after the #infobox has been remove...please help...also please let me add this i want make a situation where by the before the form comes to the web-page like 5-7seconds a loading gif image will load befor the form display in the webpage how can i do that on javascript....
  23. Hello everyone, let's see if anyone can help me out. I'm creating a page with squares and rectangles div (windows 8 style) spaced from each other 4px. Each div has a title or a mini sentence. I would like: 1 - going with the mouse over the div, it shrinks slightly and changes color, all with a transition;2 - clicking on one div, this one must increase in the vertical and horizontal size because I need that, into the div will appear text boxes where you can enter data which will return a value;3 - when the div size increases, others div should always move in an orderly manner4 - clicking on another div, the first (or earlier) should return little if possible. I don't know if I have explained myself well enough. The site has responsive desgin for pc, tablets and smartphones. I would like this javascript runs on safari, Internet Explorer, crome and firefox. I hope someone can help me out ... Thanks in advance. Andrea
  24. Hi Can someone tell me how to do a foreach and increase the "rss1" number inside this javascript? <script type="text/javascript"> function load() { var feed ="http://www.dr.dk/nyheder/service/feeds/allenyheder"; new GFdynamicFeedControl(feed, "rss1"); var feedtwo ="http://feeds.feedburner.com/d0od?format=xml"; new GFdynamicFeedControl(feedtwo, "rss2"); var feedtwo ="http://www.engadget.com/rss.xml"; new GFdynamicFeedControl(feedtwo, "rss3"); var feedtwo ="http://feeds.newzmedia.dk/c/32893/f/582669/index.rss"; new GFdynamicFeedControl(feedtwo, "rss4"); } google.load("feeds", "1"); google.setOnLoadCallback(load); </script> I also need the var feed which is the RSS url set in this widget http://pastie.org/7088004 Any help is appreciated
  25. Hello! I wanna create a form that can send sms to multiple recipient, i've created a form that uses javascript to add or remove textbox dynamically, this code successfully send sms when i fill one recipient number, but fails to send more than one recipient, and as i try to make it send sms to more than one user by making it loop, i get this error, Can someone help? i want to know how do i make this form sends sms towards multiple user Warning: Invalid argument supplied for foreach() <script language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE);//Example$gsm_send_sms = new gsm_send_sms();$gsm_send_sms->debug = false;$gsm_send_sms->port = 'COM6';$gsm_send_sms->baud = 115200;$gsm_send_sms->init();$name="CTL_TEL[]";foreach ($tel as $_POST['CTL_TEL']) {$status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]);$status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n";} else { echo "Message not sent\n";}}$gsm_send_sms->close(); //Send SMS via serial SMS modemclass gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; }}?> <html><head><title>SMS via GSM</title><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal;}.clfooter { font-family:Verdana; font-size:7pt; font-weight:normal;}h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold;}hr, .hr { color:#b0b0b0;}</style></head><body class="clbody"><h1>SMS via GSM</h1><div style="WIDTH:700px"></div><hr size="1"><?phperror_reporting(E_ALL ^ E_NOTICE);?><form action="" method="post" name="myForm"><table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr></table><br><br></form></body></html>
×
×
  • Create New...