Hi all,
I need to redirect to a specific page a after form slection butI am gettimg the error of “sPrefHome is undefined” after message is shown.
Any help is appreciated.
<!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" /--->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META Name="keywords" Content="">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" media="all" href="css/dupont_master.css" />
<script LANGUAGE="JavaScript">
<!--
function processCountrySelector(_form){
var bRememberHome = _form.remember.checked;
var sPrefHome = _form.goUrl.options[document.sendUrl.goUrl.selectedIndex].value;
var cookieName = "HomeCookie";
var path = "/";
var domain = "domain.tr";
if (bRememberHome){
var thisDate = new Date();
thisDate.setYear(9999);
thisDate.setMonth(0);
thisDate.setDate(1);
//alert ("thisDate="+thisDate);
var curCookie = cookieName + "=" + escape(sPrefHome) +
((thisDate) ? "; expires=" + thisDate.toGMTString() : "")+
((path) ? "; path=" + path : "")+
((domain) ? "; domain=" + domain : "");
//alert ("curCookie="+curCookie);
document.cookie = curCookie;
// alert("past this deal" + sPrefHome);
}
//alert(window.location.search);
document.write("<br><br><br><br><br><h3 align='center'>loading...please wait</h3>");
document.close();
setTimeout("window.location.assign(sPrefHome);", 10000);
}
//-->
</script>
</head>
<body>
<table cellspacing="15" cellpadding="0" border="0" align="center">
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><img src="imgs/header.png" /></td></tr>
</table>
<!--form name="sendUrl" onsubmit="return dropdown(this.gourl)" action="#" method="post"-->
<form name="sendUrl" method="post">
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td>
<div id="countrySelector">
<div class="selectBox">
<span class="elementTitle">Bir Ülke (Dil) Seçiniz</span> 
<select class="dropDown" name="goUrl">
<!--option value="Select" selected="selected">- Select -</option-->
<option value="IdentityManager" selected="selected">Türkiye (Türkçe)</option>
<option value="IdentityManagerEnglish">United States (English)</option>
</select>
 <a class="body01link" href="#"><img class="inlineImg" onclick="javascript:processCountrySelector(document.sendUrl);" src="imgs/go_ovr.png" alt="Go" border="0"/></a>
</div>
<input type="hidden" value="value" name="remember">
 
</div>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Hi there,
Try changing this:
setTimeout("window.location.assign(sPrefHome);", 10000);
to this:
setTimeout(function(){
window.location.assign(sPrefHome);
}, 1000);
Does that help?
James_Hibbard:
Hi there,
Try changing this:
setTimeout("window.location.assign(sPrefHome);", 10000);
to this:
setTimeout(function(){
window.location.assign(sPrefHome);
}, 1000);
Does that help?
Noap, it stays on message page and doesnt redirect.No error though.
Oh, that’s a shame.
Funnily enough it works just fine for me in the latest Chrome.
Just to be sure, try this:
<!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=iso-8859-1">
<title>Untitled Document</title>
<!--<link rel="stylesheet" type="text/css" media="all" href="css/dupont_master.css" />-->
</head>
<body>
<form name="sendUrl" method="post">
<div id="countrySelector">
<div class="selectBox">
<span class="elementTitle">Bir Ülke (Dil) Seçiniz</span>
*
<select class="dropDown" name="goUrl">
<option value="IdentityManager" selected="selected">Türkiye (Türkçe)</option>
<option value="IdentityManagerEnglish">United States (English)</option>
</select>
*
<a class="body01link" href="#">
<img class="inlineImg" onclick="javascript:processCountrySelector(document.sendUrl);" src="imgs/go_ovr.png" alt="Go" border="0"/>
</a>
</div>
<input type="hidden" value="value" name="remember">
*
</div>
</form>
<script type="text/javascript">
function processCountrySelector(_form){
var bRememberHome = _form.remember.checked;
var sPrefHome = _form.goUrl.options[document.sendUrl.goUrl.selectedIndex].value;
var cookieName = "HomeCookie";
var path = "/";
var domain = "domain.tr";
if (bRememberHome){
var thisDate = new Date();
thisDate.setYear(9999);
thisDate.setMonth(0);
thisDate.setDate(1);
var curCookie = cookieName + "=" + escape(sPrefHome) +
((thisDate) ? "; expires=" + thisDate.toGMTString() : "")+
((path) ? "; path=" + path : "")+
((domain) ? "; domain=" + domain : "");
document.cookie = curCookie;
}
document.write("<br><br><br><br><br><h3 align='center'>loading...please wait</h3>");
document.close();
setTimeout(function(){
window.location.assign(sPrefHome)
}, 500);
}
</script>
</body>
</html>
I stripped out a lot of the unnecessary HTML and corrected one or two errors.
Try saving this to a file on your PC, running it and clicking on the submit image (which should be an input[type="submit"]
or a button, BTW).
What happens?
I tried as u desc…it stays on the message page without error. Simply it doesnt redirect. I am using ie 8…
James_Hibbard:
Oh, that’s a shame.
Funnily enough it works just fine for me in the latest Chrome.
Just to be sure, try this:
<!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=iso-8859-1">
<title>Untitled Document</title>
<!--<link rel="stylesheet" type="text/css" media="all" href="css/dupont_master.css" />-->
</head>
<body>
<form name="sendUrl" method="post">
<div id="countrySelector">
<div class="selectBox">
<span class="elementTitle">Bir Ülke (Dil) Seçiniz</span>
*
<select class="dropDown" name="goUrl">
<option value="IdentityManager" selected="selected">Türkiye (Türkçe)</option>
<option value="IdentityManagerEnglish">United States (English)</option>
</select>
*
<a class="body01link" href="#">
<img class="inlineImg" onclick="javascript:processCountrySelector(document.sendUrl);" src="imgs/go_ovr.png" alt="Go" border="0"/>
</a>
</div>
<input type="hidden" value="value" name="remember">
*
</div>
</form>
<script type="text/javascript">
function processCountrySelector(_form){
var bRememberHome = _form.remember.checked;
var sPrefHome = _form.goUrl.options[document.sendUrl.goUrl.selectedIndex].value;
var cookieName = "HomeCookie";
var path = "/";
var domain = "domain.tr";
if (bRememberHome){
var thisDate = new Date();
thisDate.setYear(9999);
thisDate.setMonth(0);
thisDate.setDate(1);
var curCookie = cookieName + "=" + escape(sPrefHome) +
((thisDate) ? "; expires=" + thisDate.toGMTString() : "")+
((path) ? "; path=" + path : "")+
((domain) ? "; domain=" + domain : "");
document.cookie = curCookie;
}
document.write("<br><br><br><br><br><h3 align='center'>loading...please wait</h3>");
document.close();
setTimeout(function(){
window.location.assign(sPrefHome)
}, 500);
}
</script>
</body>
</html>
I stripped out a lot of the unnecessary HTML and corrected one or two errors.
Try saving this to a file on your PC, running it and clicking on the submit image (which should be an input[type="submit"]
or a button, BTW).
What happens?
Hi there,
The problem is your use of document.write
.
Comment out these two lines and things will work as expected:
document.write("<br><br><br><br><br><h3 align='center'>loading...please wait</h3>");
document.close();
Why document.write is [URL=“http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice”]considered [URL=“http://javascript.crockford.com/script.html”]bad
A better alternative
See also: http://www.sitepoint.com/insert-in-place-without-documentwrite/
Hope that helps.
If you need any help implementing an alternative, just let us know.
Hi there,
Your original reply was asking for help to fix this, so I did.
I see you’ve altered this in the meantime, but maybe you can use it anyway:
<!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=iso-8859-1">
<title>Untitled Document</title>
<!--<link rel="stylesheet" type="text/css" media="all" href="css/dupont_master.css" />-->
</head>
<body>
<form name="sendUrl" method="post">
<div id="countrySelector">
<div class="selectBox">
<span class="elementTitle">Bir Ülke (Dil) Seçiniz</span>
*
<select class="dropDown" name="goUrl">
<option value="IdentityManager" selected="selected">Türkiye (Türkçe)</option>
<option value="IdentityManagerEnglish">United States (English)</option>
</select>
*
<a class="body01link" href="#">
<img class="inlineImg" onclick="javascript:processCountrySelector(document.sendUrl);" src="imgs/go_ovr.png" alt="Go" border="0"/>
</a>
</div>
<input type="hidden" value="value" name="remember">
*
</div>
</form>
<div id="loading"></div>
<script type="text/javascript">
function processCountrySelector(_form){
var bRememberHome = _form.remember.checked;
var sPrefHome = _form.goUrl.options[document.sendUrl.goUrl.selectedIndex].value;
var cookieName = "HomeCookie";
var path = "/";
var domain = "domain.tr";
if (bRememberHome){
var thisDate = new Date();
thisDate.setYear(9999);
thisDate.setMonth(0);
thisDate.setDate(1);
var curCookie = cookieName + "=" + escape(sPrefHome) +
((thisDate) ? "; expires=" + thisDate.toGMTString() : "")+
((path) ? "; path=" + path : "")+
((domain) ? "; domain=" + domain : "");
document.cookie = curCookie;
}
var loadingDiv = document.getElementById("loading"),
spinner = new Image();
spinner.src = "http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif";
spinner.width = "25";
loadingDiv.innerHTML = "Loading";
loadingDiv.appendChild(spinner);
setTimeout(function(){
window.location.assign(sPrefHome)
}, 10000);
}
</script>
</body>
</html>
Only caveat, make sure you have the rights to use the loading gif.
The site I took this one from claimed it was free to use.
Are you sure?
I tried the code I provided on IE7, IE8, IE9, IE10 and it worked for me on every one.
Admittedly, the spinner resizing fails, but I would then just do that manually in a graphics program, like Photoshop.
What do you mean by “Admittedly, the spinner resizing fails, but I would then just do that manually in a graphics program, like Photoshop”?
When testing in IE, this line:
spinner.width = "25";
seems to have no effect and the spinner is displayed at its original size.
I would therefore resize the spinner image to the size which I wanted it to appear at and remove the above line.