JavaScript - Re-direct On Mysql Connection Failure
I am trying to figure out a way to have a page redirect if the mysql connection fails. The issue is that the page is already loaded and the only time this would be needed is if the user tries to perform operations on a loaded page after the session runs out.
So basically, I have a page that will allow you to search for an item using ajax, then select an item and press add which will place the item in another table displaying detailed information. Both operations connect to the database using SESSION variables to save the connection information. My goal is to use the "or die()" method to print something that will force a redirect because this could happen in a number of places in the site and I want to try and get them all in one swipe. Here is what seemed like it would be the most promising: Code: $conn = mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password']) or die("<script>location.href= '../login.php'</script>"); Unfortunately the javascript never runs.... I tried putting alerts also and nothing, but with firebug I can see they are printed. Any idea how I can ensure that the javascript is executed? Thanks in advance. Similar TutorialsI have encountered unpleasant thing. Code: var htmlfile = new ActiveXObject('htmlfile'); var window = htmlfile.parentWindow; var document = window.document; var tag = document.createElement('textarea'); tag.innerHTML = 'any non-empty string'; The example above in JScript environment throws the following exception Quote: htmlfile: Catastrophic failure Any script (JS or VBS) is down when assign the 'innerHTML' property of tags. In these examples I create the TEXTAREA tag but it does not matter. This don't work for ALL block or inline tags. Nevertheless an assignment of the 'innerHTML' property in browsers works fine (see the second example). Code: var tag = document.createElement('textarea'); tag.innerHTML = 'any non-empty string'; I have a question. Is this known bug or feature of the 'htmlfile' object? Or maybe someone of you has encountered this? From my main page, I have a dropdown-login box. Is it possible login form go to my user's control panel if the login was successful, or go to the login page if it's not? Ideally, I don't want to use a re-direct. Do I need to use ajax? Thank you! I'm just starting out with javascripting and am trying to make a Choose your own Adventure game. My goal is to have the scenes and alerts change depending on the button clicked, but I'm stuck, unfortunately. I keep getting the same alerts repeated and my image doesn't change. I think I'm missing code or have made a mistake somewhere, but have no idea what I've done wrong or left out. I don't know if this type of programming has a more specific name, too, so I wasn't sure what to search for to get help. Hopefully someone can guide me in the right direction. I've included my beginning code below. Thanks Code: <script type="text/javascript"> var curScene = "0"; function userChoice(decision){ alert(decision); /*welcomepage*/ if(curScene == 0) { alert("Welcome to the game. Chose 1 or 2."); }if(decision == 1) { alert(); curScene = 1; }else if(decision == 2){ alert(); curScene = 1; } /*Scene1*/ if(curScene == 1){ alert("go left or right"); }if(decision == 1) { alert("you went left and fell in a hole"); curScene = 3; }else if(decision == 2){ alert("you go right and come upon a zebra"); curScene = 4; } } document.getElementById("sceneimg").src= "scene" + curScene + ".jpg"; </script> <img id="sceneimg" src="scene0.jpg" alt= "Stick Figure Adventure" /> <input type="button" value="1" onClick= "userChoice(1)"> <input type="button" value="2" onClick= "userChoice(2)"> </script> I read a beginners book on js and now I'm working through a cookbook style book to get a hang of things, I came across an example for redirecting URLs in the book that didn't work: Code: <form> <input type="text" name="url"> <input type="button" value="Go" onClick="location.href=this.form.url.value"> </form> After searching on the net I found another that works perfectly but I don't understand why the one in the book doesn't work. works: Code: <form name="openlocation"> <input type="text" name="href"> <input type="button" value="Go" onClick="location.href=document.openlocation.href.value;; "> </form> I tried replacing the url with href and other tweaks, is it that you cant use ".this" here, making it necesary to name the form? Any explanation help would be apreciated. Thanks in advance! Hi Guys, Is this possible. If a page is opened and no action is taken on the page, but left open for maybe 5 min can it be re-directed to another page BUT if the page has been scrolled inside the 5 min then no action to take place. Maybe the time be reset from the last action on the page. I hope I have made that clear. Regards, The Dingbat Hi guys I have a navagation like this: Code: <ul id="nav" class="menu"> <li><a href="">Link Hover</a> <ul> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> </ul> </li> <li><a href="">Link Hover</a> <ul> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> </ul> </li> <li><a href="">Link Hover</a> <ul> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> </ul> </li> <li><a href="">Link</a></li> <li><a href="">Link</a></li> <li><a href="">Link Hover</a> <ul> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> <li><a href="">hidden</a></li> </ul> </li> </ul> Im trying to use javascript to count only the direct li children of ul. So I tried childnode but im not really familiar with it. Basically the li items inside the li should not be counted. hi i try this code it not working beacause its open after one second open new tab javascript query but i have also use php redirect url also . i want javascript new tab url open new tab before page redriect here is code Code: <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { setTimeout(function() { window.open( 'https://google.com', '_blank' ); }, 2000); }); </script> <?php $url='http://yahoo.com'; echo header ('Location:'.$url); ?> in above code i want page redirect to yahoo.com before open new tab of google.com how to set it please help me Ok, I paid to have a website built, yet the developer used iFrames to accomplish the task. Basically, load a parent page, and then in an iframe, lod content chosen from a menu. Is there a way to create a menu at the homepage level, that will allow a menu listing the various parent pages, and under each parent page, have a drop down that will point directly at an iframe content? Like this? Page1 Page2 Page3 Page1ContentA Page1ContentB Page1ContentC And when you click Page1ContentC, it will load Page1.htm and in the iframe load Page1ContentC? If i am not clear, please let me know. Any help appreciated. Jeff I've got a client using JQuery pageslide function on a wordpress site - http://srobbin.com/blog/jquery-pageslide/ There is a sidebar menu on the left and about 5 pages in the right hand side. So you click one of the links on the sidebar menu and it slides to one of the 5 corresponding pages. I guess the 5 pages are all really one page though within the slider app? I'm wondering if it's possible to link directly to a page within the slider... because right now it always goes to the first page of the 5. And is there a way to program it so the back button in the browser makes the page slide go back to the previous page, rather than going to the last actual page in the browser? Hi All, I have to know whether we can track the direct browser closing event by Javascript. I have tried with window.unload & window.onbeforeunload, but I was not get full satisfaction with those ones. Please let me know if anybody have any kind of solutions other than those specified above. advance thanks... I have 3 check boxes and one submit button when the submit button is hit I need it to direct to one of 3 pages depending on which check box is checked. can anyone help with this Thanks! I have the following script in my page Code: var tickspeed=4000 var enablesubject=0 if (document.getElementById){ document.write('<style type="text/css">\n') document.write('.dropcontent{display:none;}\n') document.write('</style>\n') } var firstDiv=0 var allDivs=0 function contractall(){ var inc=0 while (document.getElementById("dropmsg"+inc)){ document.getElementById("dropmsg"+inc).style.display="none" inc++ } } function expandone(){ var firstDivObj=document.getElementById("dropmsg"+firstDiv) contractall() document.getElementById("dropcontentsubject").innerHTML=firstDivObj.getAttribute("subject") firstDivObj.style.display="block" firstDiv=(firstDiv<allDivs-1)? firstDiv+1 : 0 setTimeout("expandone()",tickspeed) } function startscroller(){ while (document.getElementById("dropmsg"+allDivs)!=null) allDivs++ expandone() if (!enablesubject) document.getElementById("dropcontentsubject").style.display="none" } if (window.addEventListener) window.addEventListener("load", startscroller, false) else if (window.attachEvent) window.attachEvent("onload", startscroller) I also have the following in my html: Code: <div id="dropcontentsubject"></div> <div id="dropmsg0" class="dropcontent" subject=""></div> There are a total of 4 dropmsg# divs. I need to be able to input 4 navigation buttons below this code that will, when clicked, pause the ticker and go directly to the "dropmsg#" assigned to that button. I would deeply appreciate any assistance with this. Thank you. Double post I'm sorry. Please look at my other one.
Hey folks. I am needing some help with an error I'm getting from a project I'm working on. First off let me preface this all with the fact that I'm a total javascript noob. I'm really trying to understand what I'm doing wrong. So any help or advice is MORE than welcome. Here's what is happening. I found this code that will duplicate a row in a table and modifiy the name of a input in the row. Well for my purposes I have two different tables I need to work with. (each one idividually) So I changed the code a bit to make it accecpt a variable to use for the table name. (before it was static) and now I'm getting a error. Code: Error: uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER)" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: http://www.tourandtravelnow.com/admin/scripts/faxPageScript.js :: addRow :: line 14" data: no] This is the old code that would work (only for one of the tables) Code: var clone; function cloneRow(){ var rows=document.getElementById('mytab').getElementsByTagName('tr'); var index=rows.length; clone=rows[index-1].cloneNode(true); var inputs=clone.getElementsByTagName('input'), inp, i=0 ; while(inp=inputs[i++]){ inp.name=inp.name.replace(/\d/g,'')+(index+1); } } function addRow(){ var tbo=document.getElementById('mytab').getElementsByTagName('tbody')[0]; tbo.appendChild(clone); cloneRow(); } onload=cloneRow; and here is my code that doesn't work. Code: var clone; function cloneRow(mytab){ var rows=document.getElementById(mytab).getElementsByTagName('tr'); var index=rows.length; clone=rows[index-1].cloneNode(true); var inputs=clone.getElementsByTagName('input'), inp, i=0 ; while(inp=inputs[i++]){ inp.name=inp.name.replace(/\d/g,'')+(index+1); } } function addRow(mytab){ alert(mytab); var tbo=document.getElementById(mytab).getElementsByTagName('tbody')[0]; tbo.appendChild(clone); cloneRow(mytab); } onload=cloneRow(mytab); So like I said any help would AWESOME! have a great day. Kevin. On my site's shopping cart, when clicking the "buy" button, it merely animates a little item that shows that something is now in the customer's cart. I'd like it to do this, and then redirect to "/cart", cutting down the work of what the user actually has to do (we only have one product). Here's what I'm working with: <!-- START ADD TO CART --> {% if featuredproduct.available %} <span class="featured-product price"><span>{{ featuredproduct.price | money }}</span>{% if featuredproduct.compare_at_price_max > featuredproduct.price %} <del>{{ featuredproduct.compare_at_price | money }}</del>{% endif %}</span> <input type="submit" value="{{ settings.text_addtocart }}" class=" add-to-cart addtocart button primary"> {% else %} <h3 class="featured-product price sold-out"><span>Sold Out</span></h3> <input type="submit" value="{{ settings.text_addtocart }}" class="featured-product add-to-cart button primary disabled" disabled="disabled "> {% endif %} <!-- END ADD TO CART --> Adding an "onclick="location.href='/cart';" after the input classes does not fire the actual act of adding the item to the cart, so it shows an empty cart on the redirect. JS newbie, sorry for the rough explanation. Any help greatly appreciated! Hi I'm new to javascript, so this is probably very simple. I've created a form with combobox with different values (this is for my website). What I want is when the user clicks 'submit' that it goes to a different page on the website depending on the value the person has selected in the combobox. Values are numerical, for example 1000, 2000, 5000 etc. I've been trying this for a couple of days now without success! Thanks in advance Hello, I am new to javascript, I have been searching how to connect to a database and execute some queries, and then use the data that I get to populate some tables in a web page, all this using javascript. I am confused because I have seen in some webpages that javascript is not designed to connect with databases, and also I have see other pages where they say that it is possible. Does anyone know if it is possible to use javascript to connect to a database (informix), and execute some procedures or queries? Is the any tutorial a about it? Thanks i need script will detect connection speed and redirect to a page:
In the home page (index.html) i have a flash intro. The first time a user sees the website, the intro should play. Once he goes to another page (about_us or contact_us) and comes back to the home page, it should show a different swf (the version without the intro) - i have created two swf files. I need to know how to change them when the user has already seen the intro or was in the home page before. When i googled, i found something on cookies. I have no clue on how to set them and change the swf file. Would be great if someone has already done this or point me to a tutorial. i need java script. please help!!!!!!! |