JavaScript - Stumped! Please Help...js Redirection
Hi all
Sorry my first post is a question...but I hope you can help me out all the same. My name's Steve, and I have struggled (like all heck!) to figure this scenario out. I owe you a beer if you can help! OK, here's the scenario: I'm using a very basic redirect script, such as: Code: <html> <body> <script language="javascript" type="text/javascript"> function redirect(URL) { document.location=URL; return false; } </script> <a href="http://www.mywebsite.com" onclick="return redirect('http://www.mywebsite/contactme.html');">This Works</a> </body> </html> ...nothing you haven't seen a million times, right? BUT! I'd like the page I'm redirecting to (http://www.mywebsite/contactme.html) to open up an invisible iFrame, and then redirect the "parent" URL ("http://www.mywebsite.com") to an external site... So, 1) The visitor clicks on a link on my site (say, contactme.html) 2) The visitor is redirected to another page on my site (in an invisible iFrame)...e.g. mywebsite.com/processing.html 3) The iFrame loads in another invisible iFrame (for example, http://3rdpartysite.com/updatecontact.html) 4) The visitor on the contactme.html page is then redirected to a different domain (e.g. http://3rdpartysite.com/done.html) I've spent literally WEEKS trying to get this code going, and I'm now admitting defeat! I'm sure it's possible, but JS is not my specialist subject... ...at all I'd really appreciate ANY pointers, because I have a deadline to meet! Kind regards, Steve Similar TutorialsGreetings, Perhaps someone with the knowledge could assist me with this problem ... Basically, I need to put some code together to automatically redirect a page back to the referring page after a short delay ... and frankly I'm banging my head against a brick wall LOL OK ... got this in HTML to auto redirect to a specific web page after a defined delay : Code: <meta HTTP-EQUIV="REFRESH" content="10; url=http://www.****.co.uk/index.htm"> ... and I have this javascript for redirecting back to the referring page using a button : Code: <form method="POST"> input type="button" name="B1" value="Try it now" onclick="history.back();"> </form> So the question is how to combine the two so that I can get the page to return to the referring page after a delay automatically (that is, without having to press a button) ???? Any assistance would be really appreciated. Many thanks. O T T Hi all. I'm experiencing an issue with dijit.Tree/ForestStoreModel/ItemFileWriteStore and I just can't seem to figure out what's going on. If I start with an empty store model ... var myData= { "identifier" : "id", "label" : "name", "items" : [] }; var myStore = new dojo.data.ItemFileWriteStore({ data: myData }); var myModel = new dijit.tree.ForestStoreModel({ sto masterStore, query: {type: 'task'}, rootId: "tasks_id", rootLabel : "Tasks", childrenAttrs: ["children"] }); If I eventually execute newItem on the store, the tree is not updated. myStore.newItem( { id: "2", name : "someName2", type : 'task', children : [], } ); However, if during declaration of my data, I include 1 item, ie. var myData= { "identifier" : "id", "label" : "name", "items" : [ {"id" : "1", "name" : "someName", "type" : "task"} ] }; Then I can subsequent call newItem as many times as I wish, and the tree is updated correctly. If anybody has any ideas, I'm all eyes. First time posting, I hope I'm doing this right. I'm having problems with the following code, it is just a simple form but I keep getting an error message saying " my elementId is undefiened and I can not find out where I messed up. Code: <!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> <title>Form Help</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <script type="text/javascript"> /* <![CDATA[ */ function showHelp(elementID) { var curElement = document.getElementById(elementId); var helpElement = document.getElementById("box"); switch (elementId) { case "username": helpElement.innerHTML = "Enter a unique user name that is between 5 and 12 characters. "; break; case "password": helpElement.innerHTML = "Enter a password between 6 and 10 characters tht contains both upper and lowercae letters an at least one numeric character. "; break; case "password_confirm": helpElement.innerHTML = "Confirm your selected password. "; break; case "challenge": helpElement.innerHTML = "Enter your mother's maiden name. This value will be used to confirm your identity in the event that you forgot your password. "; break; } helpElement.innerHTML +="<a href=''onclick=\"document.getElementById('box').style.visibility = 'hidden';return false;\">Close</a>"; document.getElementById("box").style.visibility = "visible"; document.getElementById("box").style.left = curElement.offsetWidth + 20 + "px"; document.getElementById("box").style.top = curElement.offsetTop + "px"; } /* ]]> */ </script> </head> <body> <h1>Form Help</h1> <form action="" method="get" enctype="application/x-www-form-urlencoded"> <p><strong>User Name</strong><br /> <input type="text" id="username" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> <p><strong>Password</strong><br /> <input type="password" id="password" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> <p><strong>Confirm Password</strong><br /> <input type="password" id="password_confirm" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> <p><strong>What is your mother's maden name?</strong><br /> <input type="password" id="challenge" size="50" onmouseover="this.style.cursor='help'" onclick="showHelp(this.id)" /></p> </form> <div id="box" style="position: absolute; visibility: hidden; width: 250px; background-color:#C0FFFF; font: Comic Sans MS; color: #A00000;border:1px dashed #D00000"></div> </body> </html> It seems like it should be simple, but I don't see what I'm missing. Right now, the search button displays directly under my input field. I've gone through the CSS, but can't figure out where my code is forcing the button onto its own line. What am I missing? How can I bring it up to the same line?? Code: <form role="search" method="get" id="searchform" action="http://www.centerpie.com/" > <div> <input type="text" value="" maxlength="100" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"> </div> </form> Thanks for looking! I have a widget that lives on a blank/fresh Blogger.com account, and with test pictures, it seems to work fine. However, when I throw in Amazon ads it breaks. Images with links as sample data, rotate and display fine. Changing them to amazon code, they break. What's going on? Am I missing an escape character? Code: <script language="Javascript" type="text/JavaScript"> var ad = new Array() ad[0]=' <iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> ' ad[1]='<iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=netbooknewsco-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=B0051VVOB2" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> ' function randomorder(targetarray, spacing){ var randomorder=new Array() var the_one var z=0 for (i=0;i<targetarray.length;i++) randomorder[i]=i while (z<targetarray.length){ the_one=Math.floor(Math.random()*targetarray.length) if (targetarray[the_one]!="_selected!"){ document.write(targetarray[the_one]+spacing) targetarray[the_one]="_selected!" z++ } } } </script> <script language="Javascript" type="text/javascript" ></script> <script> randomorder(ad, ' ') </script> Hello! I have a really simple JavaScript calculator I'm running, and for the life of me can not figure out how to solve this crazy number problem. It's not doing the math properly, and javascript is not my strongest suit. All my script does is take user input of numbers into a form field, subtract that from another form and multiply the answer of those two forms by whatever the user put in. Example: 210 (minus) 120 (multiplied by) .90 = 81 Here is the actual script: Code: // Calculator function CalculateSum(Atext, Btext, Ctext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); form.Answer.value = A - B * C; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> And the html I am using: Code: <form name="Calculator" method="post"> <p>Base Average<input type=text name="input_A"></p> <p>Current Average:<input type=text name="input_B"></p> <p>Percentage of:<input type=text name="input_C"></p> <p>Your ball speed is: (miles per hour) <input name="Answer" type=text readonly> </p> <p> <input type="button" value="Calculate Handicap" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="button" value="Clear" name="ClearButton" onClick="ClearForm(this.form)"> </p> </form> Any help would be greatly appreciated! Ok so problem is that I'm using an XML generated intro for my website. My intro(index.html) is in the root directory with website home(index2.html). Issue is that I want the website to be loaded directly after intro in the same browser tab/window/page instead of a new one. Intro is using XML formatting and the Javascript being used is Asual SwfAddress 2.4 deeplinking for Flash and XML. Let me post some codes here from my website and intro; Intro.xml Code: <link url="index2.html" target="_self" /> Swfaddress.js 2.4 Where targets are set Code: {target=typeof target!=UNDEFINED?target:"_self";if(target=="_self"){self.location.href=url}else{if(target=="_top"){_l.href=url}else{if(target=="_blank"){window.open(url)}else{_t.frames[target].location.href=url}}}};this.popup=function(url,name,options,handler){try{var popup=window.open(url,name,eval(options));if(typeof handler!=UNDEFINED){eval(handler)}}catch(ex){}_popup=arguments} The intro is a template I'm using and I'm not familiar to its coding. I just want the intro to end and the website to load in the same browser window but its not happening. I've used other target options like 'parent' and 'top' but its not working. Also, on intro page there is a 'skip intro' button but when you click it intro keeps on playing and new window pop opens with the website. You can preview the website at; www.caterpowertrading.com and SWFaddress 2.4 at www.caterpowertrading.com/js/swfaddress.js No, its not using AS1-3. ~ Desperate Soul. PS: Sorry for multiple postings but its actually not! here is the link that i want to redirect http://www.xyz.com/tracks?hop=martit...e=1&varname2=2 when it will redirect the URL will be http://www.xyz.com/special?varname1=1&varname2=2 it's mean the hop and redirection variable will be remove from querystring, special is a page, it will take value from redirection variable, nothing will be hardcode. I'm facing a validation error, whenever I leave any of the fields blank, it gives me a warning and then it redirects me to (index.php?option=com_ccnewsletter&view=ccnewsletter) What I wanna know is how can I freeze the page until all fields are filled? This is the javascript code: Code: <script type="text/javascript"> function formsubmit(task) { var form = document.subscribeFormModule; if(task == "addSubscriber") { if(form.name.value== "") { alert('<?php echo $parameters['namewarning']; ?>'); } else if(form.email.value == "") { alert('<?php echo $parameters['emailwarning']; ?>'); } else if(( form.email.value.search("@") == -1) || ( form.email.value.search("[.*]" ) == -1 )) { alert('<?php echo $parameters['emailwarning']; ?>'); } <?php if($parameters['showterm']) { ?> else if(form.terms_condition_ch.checked == false) { alert ('<?php echo $parameters['terms_cond_warn']; ?>'); } <?php } ?> else { form.task.value = "addSubscriber"; form.submit(); } } else if(task == "removeSubscriberByEmail") { if(form.email.value == "") { alert('<?php echo $parameters['emailwarning']; ?>'); } else if(( form.email.value.search("@") == -1) || ( form.email.value.search("[.*]" ) == -1 )) { alert('<?php echo $parameters['emailwarning']; ?>'); } else { form.task.value = "removeSubscriberByEmail"; form.submit(); } } } </script> And this is the form's code: Code: <div class="mainnewsletter"> <p><?php echo $parameters['introduction'] ?></p> <div class="module" style="padding-top: 0px;"> <div class="normalsublayout"> <form class="form-login" action="<?php echo JRoute::_('index.php?option=com_ccnewsletter&view=ccnewsletter');?>" method="post" name="subscribeFormModule" id="subscribeFormModule"> <p><div> <?php echo $parameters['name']; ?>: <div class="username-block"> <div class="input-field-l"> <input class="inputbox" type="text" onblur="if(this.value=='') this.value='YourName';" onfocus="if(this.value=='YourName') this.value='';" name="name" id="name" value="<?php echo $name; ?>" /> </div></div> </div> </p> <p> <div> <?php echo $parameters['email']; ?>: <div class="password-block"> <div class="input-field-l"> <input class="inputbox" type="text" onblur="if(this.value=='') this.value='youremail@domain.com';" onfocus="if(this.value=='youremail@domain.com') this.value='';" name="email" id="email" size="15" maxlength="35" value="<?php echo $email; ?>" /> </div> </div> </div> </p> <?php if($parameters['showterm']) { ?> <p> <input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox"> <a style="font-size:14px;color:#4E4E51; display: margin:0px 0px 0px 5px;text-decoration:none;" href='<?php echo $cid; ?>' class="modal" rel="{handler: 'iframe', size: {x: 700, y: 375}}"><?php echo $terms;?></a> </p> <?php } if($unsubscribe) { ?> <p> <input class="button" type="submit" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>" onclick="formsubmit('addSubscriber');"/> </p> <p><input class="button" type="submit" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo $parameters['unsubscribe']; ?>" onclick="formsubmit('removeSubscriberByEmail');"/> </p> <?php } else { ?><div class="readon-wrap1"> <div class="readon1-l"></div> <span class="readon-main"><span class="readon1-m"><span class="readon1-r"><input class="button" type="submit" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>" onclick="formsubmit('addSubscriber');"/></span></span></span></div> <!--<p><center><input type="image" src="images/back_f2.png" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>" onclick="formsubmit('addSubscriber');"/></center></p>--> <?php } ?> <input type="hidden" name="option" value="com_ccnewsletter" /> <!--<input type="hidden" name="task" value="addSubscriber" />--> <input type="hidden" name="task" value="" /> </form> </div> </div></div> I don't know, maybe I'm missing something because it was working fine a before. Morning Guys, i have a little issue i need to tackle and i belive Javascript is the way forward on this, so looking for some pointers/help on the idea i have in mind. so basically i have a website and its going to be selling severall products. now i have a "Global" navigation which stays the same on every page throughout the website. now obviously if this is set into the master template all the links will be the same. 1 of my links will be a "buy now" button, i want this to never need changing but i want the link to direct to the correct purchasing page depending on which product is being described in the content area... so im guessing its going to need to fetch some sort of Value/Variable out the content and then use that to redirect to the correct page via that single "buy now" button.. any ideas or input cheers, ant. Hi, I am wanting to install an automatic re-direction script. I have seen some pretty complicated ones and then I came across this: Code: <script type="text/javascript"> <!-- if (screen.width <= 699) { document.location = "mobile.html"; } //--> </script> Is that going to work ? Thanks . I'm a non-web programmer being forced to do some web programming. My immediate problem is that, on submission of a form, I need to be able to open a url (that I control) with the filled-in form values appended to the new url. In other words, I need to be able to do the equivalent of : Code: <form> <input name="key1" type="text"/> <input name="key2" type="text"/> <input type="button" value="Submit" onclick="window.open('http://new.domain.com/newpage.html?key1=val1&key2=val2')"/> </form> I would really like to do this without server-side code. Pointers? TIA Hello all! As it could not be otherwise, in my first post here, I have a horribly simple problem... I'm currently working on a homepage for my browser, where I have many frequently used links, and I'm trying to implement some search engines too. The one I'm working on is simply, a predefined URL, and the input text string at the end. For example: "http://www.example.com/search/(textinput)" This is the code I have so far: Code: <script type="text/javascript"> function gosearch() { var srchstring = document.getElementById('string').value; var resulturl = 'http://www.example.com/search/' + srchstring; window.location.href = resulturl; } </script> <form name="searchform" onsubmit="gosearch();"> <input id="string" size="31" maxlength="255" value="" /> <input type="submit" value="Search!" /> </form> But what happens by using this code, is that, to the current URL, a "?" gets added, as if the code tried to send some info using GET. I could do this quite easily using PHP, but as I want to use this locally, I cannot use any server-side code... Besides the fact that I want to learn some JScript too. Thanks for your help. Hi, I want to write a javascript program which will redirect the user from a welcome page to an an intro page when a cookie is found. If there are not cookies found, the welcome page is loaded but a cookie is written so that next time the user visits the page, he will be redirected to the intro page automatically. This program would allow only new visitor to view the welcome page and other visitors to skip the welcome page to be brought to the intro page right away. I am a newbie and here is the code which I have though of so far. Can someone expand on it? Thanks The Apprentice Code: window.onload = pageInit; function pageInit(){ var visited = ""; if (document.cookie !=""){ window.location = "introPage.htm"; } else{ setCookie(); } function setCookie(){ document.getElementById("click").onclick = cookie; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 6); hello, I am trying to figure out how to hide the direction page in this code: I want to hide: www.ipage.com/mail/index.bml <INPUT TYPE="submit" NAME="Log In" VALUE="Check Mail" onclick="javascript:login.action='http://www.ipage.com/mail/index.bml?s=1';javascript:login.destination.value = '/mailadmin/index.bml?check=1';" > </TD> <TD> <INPUT TYPE="submit" NAME="Log In" VALUE="Manage Mail" onclick="javascript:login.action='https://secure.ipage.com/mailLogin';javascript:login.destination.value = '/mailadmin/index.bml?manage=1';"> any help is appreciated.... Hey guys, So I'm currently trying to make a page redirect using the following code: Code: <img src=foo.png onerror=location.replace('%68%74%74%70%3A%2F%2F%67%6F%6F%67%6C%65%2E%63%6F%6D');> The encoded html part is simply a link http://google.com The code works fine so far on all browsers. But the problem is that it redirects wrongly. It should be redirecting to http://google.com Instead, it takes me to http://mysite.com/http://google.com How do I fix this? Thanks a lot P.S: I cannot use any code for redirection that has an (=) equals sign Which means I can't use location.href='http://google.com' Hello. My goal is for the user's input on their first visit to redirect their landing page in the future. I am a novice and any help is very much appreciated. The form's drop down menu includes three cities (Calgary, Toronto, Vancouver). When the user presses "submit form", the script should create a cookie to store the user's city selection. Next time the user visits the site, they should be redirected to their city's site, ie. "/vancouver.html" Right now, the code is returning an error from the onload("redirect();") function. The error indicates I am trying to redirect to "/[object HTMLSelectElement].html", but I am not sure if the trouble is in reading or writing the cookie. For simplicity, I've removed most of the other content from this page (my cookie.js is attached as a .doc): Code: <title>Site Title</title> <script type="text/javascript" src="cookie.js"></script> <script language="JavaScript" type="text/javascript"> function redirect() { userCity = readCookie ("user_city"); if (userCity) { window.location.replace(userCity + ".html"); } else { window.location.replace("index.html"); } } function setCity(box) { { var userCity =(document.welcomeSignUp.userCity); for (i=0; i<userCity.length; i++) { if (userCity[i].name != box.name) { userCity[i].selectedIndex = 0; } } } writeCookie("user_city", userCity, 5 * 365); } </script> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <form id="welcomeSignUp" action="" method="get" name="welcomeSignUp" onload="redirect();"> Your Email address: <input type="text" name="email" value="" size ="20" /> <br /> Choose Your City: <select name="userCity" size="20"> <option value="one">Calgary</option> <option value="two">Toronto</option> <option value="three">Vancouver</option> </select> <a href="index.html"><button class="rounded" onclick="setCity(this);"> <span>submit form</span> </button></a> </form> </body> </html> I have a form in an iframe that submits nicely. Here is one of the hidden fields that gives the page to redirect to after submitting the form: Code: <input type="hidden" name="rtrn" value="http://www.domain.com/thanks.html" target="_parent"> The parent target doesn't work, does anyone know how I get the thanks page to replace the page containing the iframe? |