JavaScript - Execute Php Page From Javascript
Quote:
Originally Posted by mlseim hmmm .... sort of stumped. For a test, I made a script that pulls a random "bumper-sticker" quote out of a file and sends it back as Javascript. Put this on a test page of yours and see what happens: <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> Wherever that line is, when you view your web page, it should have a random quote. It's using the same code that I had above (in post #2). how would you put <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> into a function for javascript to call this php file? Similar TutorialsFirst off; i was in two minds if this belonged in the .php forum or the javascript forum; i apologize if i chose the wrong one. I have this .php code: PHP Code: <?php $query = "SELECT mail_id FROM ".TBL_MAIL." WHERE UserTo = '$session->username' and status = 'unread'"; $numUnreadMail = $database->query($query) or die(mysql_error()); $numUnreadMail = mysql_num_rows($numUnreadMail); if($numUnreadMail == 0){ echo '<img src="../images/global/mail_imgs/inbox_0.png" width="22" height="15" />';} if($numUnreadMail == 1){ echo '<img src="../images/global/mail_imgs/inbox_1.png" width="22" height="15" />';} if($numUnreadMail == 2){ echo '<img src="../images/global/mail_imgs/inbox_2.png" width="22" height="15" />';} if($numUnreadMail == 3){ echo '<img src="../images/global/mail_imgs/inbox_3.png" width="22" height="15" />';} if($numUnreadMail == 4){ echo '<img src="../images/global/mail_imgs/inbox_4.png" width="22" height="15" />';} if($numUnreadMail == 5){ echo '<img src="../images/global/mail_imgs/inbox_5.png" width="22" height="15" />';} if($numUnreadMail == 6){ echo '<img src="../images/global/mail_imgs/inbox_6.png" width="22" height="15" />';} if($numUnreadMail == 7){ echo '<img src="../images/global/mail_imgs/inbox_7.png" width="22" height="15" />';} if($numUnreadMail == 8){ echo '<img src="../images/global/mail_imgs/inbox_8.png" width="22" height="15" />';} if($numUnreadMail == 9){ echo '<img src="../images/global/mail_imgs/inbox_9.png" width="22" height="15" />';} if($numUnreadMail == 10){ echo '<img src="../images/global/mail_imgs/inbox_10.png" width="22" height="15" />';} if($numUnreadMail == 11){ echo '<img src="../images/global/mail_imgs/inbox_11.png" width="22" height="15" />';} if($numUnreadMail == 12){ echo '<img src="../images/global/mail_imgs/inbox_12.png" width="22" height="15" />';} if($numUnreadMail == 13){ echo '<img src="../images/global/mail_imgs/inbox_13.png" width="22" height="15" />';} if($numUnreadMail == 14){ echo '<img src="../images/global/mail_imgs/inbox_14.png" width="22" height="15" />';} if($numUnreadMail == 15){ echo '<img src="../images/global/mail_imgs/inbox_15.png" width="22" height="15" />';} if($numUnreadMail == 16){ echo '<img src="../images/global/mail_imgs/inbox_16.png" width="22" height="15" />';} if($numUnreadMail == 17){ echo '<img src="../images/global/mail_imgs/inbox_17.png" width="22" height="15" />';} if($numUnreadMail == 18){ echo '<img src="../images/global/mail_imgs/inbox_18.png" width="22" height="15" />';} if($numUnreadMail == 19){ echo '<img src="../images/global/mail_imgs/inbox_19.png" width="22" height="15" />';} if($numUnreadMail == 20){ echo '<img src="../images/global/mail_imgs/inbox_20.png" width="22" height="15" />';} //Middle Section echo '</a> <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">'; if($session->isAdmin()){ echo '<a href="http://localhost/admin/admin_mailinbox.php">View Inbox ';} else{ echo '<a href="http://localhost/mailinbox.php">View Inbox ';} //Displays the correct number on drop tab if($numUnreadMail == 0){ echo ' ';} if($numUnreadMail == 1){ echo '(01)';} if($numUnreadMail == 2){ echo '(02)';} if($numUnreadMail == 3){ echo '(03)';} if($numUnreadMail == 4){ echo '(04)';} if($numUnreadMail == 5){ echo '(05)';} if($numUnreadMail == 6){ echo '(06)';} if($numUnreadMail == 7){ echo '(07)';} if($numUnreadMail == 8){ echo '(08)';} if($numUnreadMail == 9){ echo '(09)';} if($numUnreadMail == 10){ echo '(10)';} if($numUnreadMail == 11){ echo '(11)';} if($numUnreadMail == 12){ echo '(12)';} if($numUnreadMail == 13){ echo '(13)';} if($numUnreadMail == 14){ echo '(14)';} if($numUnreadMail == 15){ echo '(15)';} if($numUnreadMail == 16){ echo '(16)';} if($numUnreadMail == 17){ echo '(17)';} if($numUnreadMail == 18){ echo '(18)';} if($numUnreadMail == 19){ echo '(19)';} if($numUnreadMail == 20){ echo '(20)';} ?> which displays in this navigation: <li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()" class="link_image"> <?php include_once('../include/mailicon_codes.php'); ?> </a> I wondered how or if it is even possible to use javascript to execute the first .php code so that the user would know if he/she had a new message without refreshing the page? Any help is greatly appreciated as i suck at .js cheers, Callum FF, Safari, Opera all execute this javascript code to refresh the page properly, but in IE version 8.0.6001.18904 the page doesn't seem to refresh on click of orange_refresh button. I have checked out a different version of IE8, don't recall exact version, but it did seem to work fine in that one, whatever version it was probably the latest now that I think of it. Check out code below any sug.'s could be helpful, though its probably a bug.. Code: <a href="javascript:document.location.reload();" onmouseover="window.status='Refresh'; return true" onmouseout="window.status='Page Refreshed'"><img src="image/orange_refresh.png" width="30" height="30" border="0" /></a> I am wondering if its possible to execute a JavaScript script as soon as the page is loaded? Perhaps a generic execution? I tried this, but it didn't work: Code: <SCRIPT type="text/javascript"> if (document.forms["form"]["quantitym"].value > '.$row['sizem'].') { alert ("The quantity for product $row['id'] is no longer available."); } </SCRIPT> <FORM action="updatecart.html" method="post" name="form"> <DIV> <B>Medium:</B> <INPUT name="quantitym" value="'.$content['sizem'].'"> </DIV> </FORM> This is for my shopping cart system. The idea is, the customer might have 4 items in his cart, but whilst he was shopping, someone might of bought the same item, result in only 3 being available, but his cart still says 4. My solution to this is to make a script run through out his shopping when ever the cart items are listed and just prior payment execution, if the quantity he wants is no longer available, he will be alerted. $row['sizem'] is PHP drawing how many items there are from my stock database. If the value of the INPUT exceeds this availability, JavaScript shall alert. Does anyone know why it isn't alerting? Hi, I'm doing something wrong, I want my script to execute when the browser window opens, can someone please help me? Code: <p><iframe id="myFrame" style="display: none;" width="500" height="300"></iframe> <script type="text/javascript">// <![CDATA[ window.onload=openpdf(); type="text/javascript">// <![CDATA[ function openPdf() { var omyFrame = document.getElementById("myFrame"); omyFrame.style.display="block"; omyFrame.src = "myFile.pdf"; } // ]]></script> I wish to change the dynamic text in a javascript to that which is in a MySQL database using PHP. this is then used in a flash scroller. currently i have hard coded the text in the javascript file. is there a way to have PHP run in the javascript file before it is sent to the endusers? or another way ? Hi, I'd like to create a textarea and a division so that whatever embed code you put in the textarea it gets executed on the division in real-time. Your kind help is greatly appreciated! JavaScript newbie Hey all, so im working on a piece of jquery/JS which executes (drops down a new div) when you click a link. I have the links setup as <a href="#" id="d0">Execute 1</a> <a href="#" id="d1">Execute 2</a> <a href="#" id="d2">Execute 3</a> And the jscript detects when d0, d1 or d2 is clicked and executes my script. It all works perfectly, however when you click on a link it will jump to the top of the page as a side effect of the a href="#" I assume? Is there anyway to have my same effect work inline (without jumping the page to the top) ? Thank you very much! HI peers, i need to run a sql query fromjavascript onclick button and display data in a textarea . is this possible ? than you . Hi, I am Aditya. I am explaining below the exact scenario where I need the help: I am developing a web application in which I need to integrate a javascript/html editor on some of the web pages and then provide 'Edit' buttons on those web pages so that users can edit the content on that partciular html/jsp page (like editing in wiki pages) and then, when they add some content and click on submit button, the new content should appear on the web page with all the formatting (i.e. bold, italics, color and so on) which was applied by user when he was entering the text. Now, I need help for the below issues: 1. Please suggest me a good javascript/html editor (freely downloadable) which I can use to integrate with my web pages. 2. Once the user has entered some content using the above javascript editor, how to make that content reach the server and update the corresponding web page. I am new to web development, so may be that these questions are too simple. But, I need some help from you. Waiting for your reply, Thanks, Aditya hi From inside a javascript function i need to execute a vbscript sub routine. You might be thinking why i can't do it in javascript. well i probably can but i am better at VBscript and it would be a lot easier. Thanks edit:: got it to work setting inBooth to false in the function where I clear the menu, but then it's refreshing to div so often while you're standing in the booth (30 frames/sec, it's a game) that nothing happens when you click the buttons to buy/sell unless you click really really fast.... anyone know a good way to check whether something is true, then toggle an innerHTML div, then once the value becomes false, toggle the innerHTML div to empty....??simply?? But if I reverse the order the opposite works but then the other doesn't...... Code: if (condition==true ) { generateSale(); inBooth=true; smithShop(); } else {inBooth=false;clearSale();} //IS PLAYER IN VENDOR BOOTH? if (condition2==true ) { generateSale(); inBooth=true; vendorShop(); } else {inBooth=false;clearSale();} Only the "generateSale()" from the second one executes. If I switch the if blocks, the second one with "generateSale()" executes. If I change "clearSale();" to a "setTimeout=('clearSale()',1000)" then both execute "generateSale()" but the div it affects flickers repeatedly as it's cleared/remade. generateSale() changes the innerHTML of a div, clearSale() just overwrites the innerHTML with ' ' Code: var sales2; function clearSale() { sales2=document.getElementById('sales2'); sales2.innerHTML=''; } function generateSale(){ sales2=document.getElementById('sales2'); sales2.innerHTML= 'Buy/Sell: '+' Gold coins: '+playerInventory[lootArray[7]]+'<br>' +' Consumables:<br>' +'You have: '+playerItems[itemArray[4]] +' arrows<br>' +'<input type="button" value="Buy" onclick="buyIt(0);">'+'10 for 50gp<br>' +'<input type="button" value="Sell" onclick="sellIt(0);">'+'10 for 25gp<br>' } Any ideas? Basically when my character enters the range of an image of a building I have a menu pop up saying you're in a vendor booth. I want it to run generateSale() which changes a div on the screen to list a bunch of stuff you can buy/sell. When your character is no longer standing in range, I want it to clear that information, so you have to be standing within range in order to trade items. Currently I can make it generates the sale menu, but it doesn't clear it when you leave the range. I've tried all kinds of "toggle" variables to set whether you're in range or not, but only the second block fires, not the first and I cannot figure out why... Any ideas? The code all works fine it just won't clear for all the different buildings, only one.... Hello, I don't know if this can be done in Javascript, or requires any other language but i was wondering if this would be possible. I would like to embed this Javascript code in to a PHP file and then for it to run automatically upon the PHP file loading: Code: <td class="smallDesc"> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </td> The Javascirpt is the Facebook Share button that basically allows users that have Facebook to share the page there currently on in their Facebook status by pressing the button, but if there not logged in it shows the login page, not a problem just continue the script. The current button i which is what i want to load automatically in the PHP file is located here, to test the functionalilty just click "Share" button in blue.. http://watch-movies-online.anyfilman...-Movie-17.html To summarise, i would like the above Javascript code to execute automatically upon pageload of this PHP file.. http://www.watch-movies-online.anyfi...p://google.com. If that could be done, and if this also is possible.. i would like for the "Share" button on the external page that is loaded from the Javascript code above to be clicked automatically so in effect when ever someone visits the PHP page after clicking "Click Here to Watch/Stream 2012 Online For Free" on this page it will automatically load the Facebook Share box, and automatically click the "Share" Button and then close the page if possible, but not required. Please feel free to ask any questions, i'll be happy to answer. Thanks in advance. Best Regards, Jonathan. hello guys the idea is to make "offline" bill of lading i used to do php thing and well this time i only need to kinda make bill of lading generator so i want to pass value from page 1 to page 2 and to page . all offline without web server interaction i was never fluent in javascript and i wanted to get a quick start from you guys how do i pass the form ( javascript variable from 1 page to another page ) i am googling this as well right now and hoping answer from codingforums thanks I have the following function: Code: function sonKare(sayac, oteki) { var vertical, horizontal = hangiYataySira(sayac, oteki), j, k, l, m, united, tekRakam, actualV = [], actualH = [], numaralar = [1, 2, 3, 4, 5, 6, 7, 8, 9], olmayanlar = []; if(ilkSefer === true) { vertical = hangiDikeySira(rakamlar.length); ilkSefer = false; } else { vertical = hangiDikeySira(rakamlar.length - 1); } for(j = 0; j <= vertical.length - 1; j ++ ) { if(rakamlar[vertical[j]] !== undefined) actualV.push(rakamlar[vertical[j]]); } for(k = 0; k <= horizontal.length - 1; k ++ ) { if(rakamlar[horizontal[k]] !== undefined) actualH.push(rakamlar[horizontal[k]]); } united = actualV.concat(actualH); //---- Olmayan rakamları bulan kısım ------------ outer: for(l = 0; l <= numaralar.length - 1; l++) { for(m = 0; m <= united.length - 1; m++) { if(numaralar[l] === united[m]) continue outer; if(m === united.length - 1 && numaralar[l] !== united[m]) olmayanlar.push(numaralar[l]); } } //---------------------------------------------- if(olmayanlar.length > 1 || olmayanlar.length === 0) { rakamlar = []; document.form1.buton.click(); // THIS LINE DOES NOT WORK SECOND TIME } else { $("_" + oteki + "_" + sayac).value = olmayanlar[0]; rakamlar.push(olmayanlar[0]); sayac++; if(sayac === 10) return; else sonKare(sayac, oteki); //CALLS ITSELF } } This is a recursive function. As stated above there is a line which does not work for the second time. What I mean is, it works perfect for the first time and after function calls itself, it doesn't work. Javascript does execute the line above it but just disregards that document.form1.buton.click(); line. I use Firebug for debugging and I checked it many times, when that expression needs to be executed for the second time, JavaScript just ignores it and immediately goes at the end of the function... I just can't figure out why JS does such a thing? p.s: Don't bother about weird variable names, they are not in English but in Turkish which is my native language Im alright with .php but not good at javascript at all. this is the javascript code placed in the head tags of my page function confirmation() { var answer = confirm("Delete news item?") if (answer){ window.location = "main.php?id=delete¬e="+noteID+"&status=delete"; } else{ alert("No action taken") } } this is the .php that links to the javascript function PHP Code: if($this->admin){ echo ' <a href="?id=edit¬e='.$this->noteID.'&status=load" class="grey">[Edit]</a>' .'<a href="" onclick="confirmation('.$row['noteID'].')" class="grey">[Delete]</a>'; } this is the .php code that executes if the url is status=delete PHP Code: // This displays if id = Delete A News & user=ADMIN if( $id == "delete" && $session->isAdmin() ) { echo '<div id="major_game_news_header">'; echo '<h1>DELETION OF NOTE</h1></div>'; $stat = $_GET['status']; if($stat == "preview" && $session->isAdmin() ) { $noteID = $_GET['note']; echo '<div id="createnews">Are you sure? <a href="?id=delete¬e={$noteID}&status=delete">' .'Yes</a>. <a href="main.php">No</a></div>'; } if($stat == "delete" && $session->isAdmin() ) { $note->deleteNote();} } this line in the third code snippet works perfect: " PHP Code: <a href="?id=delete¬e={$noteID}&status=delete">Yes</a> " I'm having great difficulty for the "window.location =...... " to navigate to the right url. It doesn't include the noteID which enables me to delete news items. Any help would be greatly apreciated (: For example, how can I write "Hello!" on the page every Friday at 8:40?
All, I have a script that runs some jQuery and appends it to a <div>. I only want this script executed if a user is using IE7 or higher since jQuery doesn't work with IE6. How can I do that? Also, if they aren't using IE7 or higher I don't wnat to display the <div> that the results go into. How would I go about doing this? Thanks! Hello: I have an ajax file to loads the content of another file into a div, here is the js code: PHP Code: <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getcar.php?q="+str,true); xmlhttp.send(); } </script> the file within xmlhttp (getcar.php) has other js codes that are to be executed once the file is loaded into the div. here is one of those files: PHP Code: <!-- loading, please wait message script begins--> <div id="loading\" class=\"loading-invisible\" z-index: 999> <p><font color=\"black\" size='4'>one moment, please!</font> <font color=#218868> Auto Tech Pro « Initiating... » </font><br /><img border='0' src='images/spinnnnnn.gif' width='215px' height='206px'> </div> <script type=\"text/javascript\"> document.getElementById(\"loading\").className = \"loading-visible\"; var hideDiv = function(){document.getElementById(\"loading\").className = \"loading-invisible\";}; var oldLoad = window.onload; var newLoad = oldLoad ? function(){hideDiv.call(this);oldLoad.call(this);} : hideDiv; window.onload = newLoad; </script> <!-- loading, please wait message script ends--> <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></script> <script src=\"/AJAX/popBox1.2.0.js\" type=\"text/javascript\"></script> <link href=\"/AJAX/popBox1.2.0.css\" rel=\"stylesheet\" type=\"text/css\" /> <script type=\"text/javascript\"> $(document).ready(function () { $('#inputbox').popBox({width:550, newlineString: '<br/>' }); }); </script> this however is not working. If I open getcar.php independently of the ajax, the preceeding js codes work fine, but not once the ajax loads the file into div. Any thoughts on how this is doable? Mossa Hey guys, I scripted a javascript guessing game and I am not sure how I can configure the random number generator to only generate one number and then stop. Here is my code: Code: <html> <head> <title>Guess it up! </title> </head> <body> <center> <BODY onLoad="GenerateNumber()"> <b><font size="5" ><u><b>Guess it up!<br></b></u> <br > <font size="3"> This is out of: <br> <input id="DefaultNumber" name="DefaultNumber" type="text" size=3><br> Type in your guess: <br> <input id="HisGuess" name="HisGuess" type="text" size=3> <p> <input name="StartButton" type="button" value="Guess" onclick="StartGame()"> </p> <script type="text/javascript"> function GenerateNumber() { var TheRightGuess = Math.round(Math.random() * (document.getElementById("DefaultNumber").value))+1; //Makes the randomly generated right guess. The "+1" makes it 1-5 instead of 0-4. } function StartGame() { var TheRightGuess = Math.round(Math.random() * (document.getElementById("DefaultNumber").value))+1; //Makes the randomly generated right guess. The "+1" makes it 1-5 instead of 0-4. var HisGuess = parseInt(document.getElementById("HisGuess").value);//his guess var DefaultNumber = parseInt(document.getElementById("DefaultNumber").value);//number that they want to guess in. //NUMERIC TEST STARTS HERE if (HisGuess != parseInt(HisGuess) || (DefaultNumber != parseInt(DefaultNumber))) { alert("Please enter numbers only.") } //NUMERIC TEST ENDS HERE if (DefaultNumber <= 0) //Fixed bug:Guessing in zero. { alert("You can't guess in zero!?") } else if (DefaultNumber === 1 && HisGuess === 1 || TheRightGuess == HisGuess && DefaultNumber != 1)//testing if they guessed in 1 and guessed 1. { alert("You got the number!") } else if (HisGuess > DefaultNumber)//if guess is higher then what they guess in. { alert("You can only guess below " + DefaultNumber + ".") } else if (HisGuess != TheRightGuess && HisGuess <= DefaultNumber && DefaultNumber != 1 || HisGuess == 0)//fixed bug: you can't guess 0. { alert("Guess again!") } } </script> </body> </html> Thanks, Fizz Hi Everyone, I want to execute a script when the user clicks the button. Currently in my html doc. i have the button declared. <input type="button" id ="button" onclick='notEmpty() value="Play"/> When the button is clicked, i execute the notEmpty() function and I want to execute a script inside the notEmpty(). How can i do this? Thanks, Praveen |