Click to See Complete Forum and Search --> : redirection specified by form element


cmotor
07-04-2003, 11:41 AM
I want users to be reirected to: http://www.mypage.com/maillist.remove_confirm.html only when they have selected the remove checkbox. Otherwise they will be redirected to the page specified in the form tag.
Please see the code below.

Thanks
-cmotor


<html>
<head>
<title>Mailing List/Join</title>
<script language="JavaScript">
function isValidEmail(email) {
invalidChars = " /:,;"
if (email == "") { // cannot be empty
return false
}
for (i=0; i<invalidChars.length; i++) { // does it contain
any invalid characters?
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf("@",1) // there must
be one "@" symbol
if (atPos == -1) {
return false
}
if (email.indexOf("@",atPos+1) != -1) { // and only one "@"
symbol
return false
}
periodPos = email.indexOf(".",atPos)
if (periodPos == -1) { //
and at least one "." after the "@"
return false
}
if (periodPos+3 > email.length) { // must be at
least 2 characters after the "."
return false
}
return true
}

function checkform() {

if (!isValidEmail(Fmaillist.email.value)) {
alert("Not a valid email address")
Fmaillist.email.focus()
}
else {
Fmaillist.submit()
}
}

</script>
</head>

<body bgcolor="#FFFFFF">
<form name="Fmaillist" action="http://www.mypage.com/cgi-
sys/FormMail.cgi" method="POST">
<input type=hidden name="recipient" value="sales@mypage.com">
<input type="hidden" name="redirect"
value="http://www.slp/join_confirm.html">

<input type="textfield" name="email" size="30" maxlength="40">
<input type="checkbox" name="remove" value="yes">
<a href="javascript:checkform();">SUBMIT</a>
</form>
</body>
</html>

SlankenOgen
07-04-2003, 12:19 PM
if(document.FormName.CheckboxName.checked == true)
{
// gothere
}else{
//go somewhere else
}

or

document.location.href = (document.FormName.CheckboxName.checked == true)?"http://www.blah.com":"http://www.blahblah.org";

cmotor
07-04-2003, 12:53 PM
1. do I have the syntax correct?

2. Where in my original code would I place this new code?

Thanks
-cmotor


document.location.href = (document.Fmaillist.remove.checked == true)?"http://www.mypage.com/maillist_remove_confirm.html":"http://www.mypage.com/maillist_join_confirm.html";

SlankenOgen
07-04-2003, 01:08 PM
Place it at the end, after the form submit. Don't know if your syntax is correct, you'll have to check it.

cmotor
07-04-2003, 01:20 PM
Does this look right?
thanks

<script language="JavaScript">
function isValidEmail(email) {
invalidChars = " /:,;"
if (email == "") { // cannot be empty
return false
}
for (i=0; i<invalidChars.length; i++) { // does it contain
any invalid characters?
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf("@",1) // there must
be one "@" symbol
if (atPos == -1) {
return false
}
if (email.indexOf("@",atPos+1) != -1) { // and only one "@"
symbol
return false
}
periodPos = email.indexOf(".",atPos)
if (periodPos == -1) { //
and at least one "." after the "@"
return false
}
if (periodPos+3 > email.length) { // must be at
least 2 characters after the "."
return false
}
return true
}

function checkform() {

if (!isValidEmail(Fmaillist.email.value)) {
alert("Not a valid email address")
Fmaillist.email.focus()
}
else {
Fmaillist.submit()
document.location.href = (document.Fmaillist.remove.checked == true)?"http://www.screamingleather.com/maillist_remove_confirm.html":"http://www.screamingleather.com/maillist_join_confirm.html";
}
}

</script>

cmotor
07-04-2003, 01:24 PM
Hey. Guess what? It works! Cool! Sorry to have made my last post before checking out myself.


Thanks again.
-cmotor

SlankenOgen
07-04-2003, 01:32 PM
You're welcome.

cmotor
07-04-2003, 01:49 PM
Ooops. One more problem.

The code redirects fine, but the form does not get submitted to the server when that line of code is in. I tested it both ways with and without the redirection code. What needs to be done so that the form will be submitted to the server?

Thanks
-cmotor

SlankenOgen
07-04-2003, 02:00 PM
It's probably because the page is exiting b4 the form has time to submit.

try

.
.
.
.
else {
Fmaillist.submit();
setTimeout("nextPage()", 1000);
}
}

function nextPage(){
document.location.href = (document.Fmaillist.remove.checked == true)?"http://www.screamingleather.com/maillist_remove_confirm.html":"http://www.screamingleather.com/maillist_join_confirm.html";
}

cmotor
07-04-2003, 02:40 PM
Now whats happening is the form is submitting, but the page is not redirecting.



else {
Fmaillist.submit();
setTimeout("nextPage()", 1000);
}
}
function nextPage(){
document.location.href = (document.Fmaillist.remove.checked == true)
?"http://www.screamingleather.com/maillist_remove_confirm.html":"http://www.screamingleather.com/maillist_join_confirm.html";
}

SlankenOgen
07-04-2003, 02:57 PM
I think it's because the checkbox is being unchecked on submit. Try this.

Outside all your functions make a global variable-

var isChecked = false;

Then-

else {
isChecked = document.Fmaillist.remove.checked; // returns true/false.
Fmaillist.submit();
setTimeout("nextPage()", 1000);
}
}


function nextPage(){
window.alert("nextPage called successfully");
document.location.href = (isChecked == true)
?"http://www.screamingleather.com/maillist_remove_confirm.html":"http://www.screamingleather.com/maillist_join_confirm.html";
}

cmotor
07-04-2003, 05:23 PM
It's still not working. Latest results based on the script below: form submits, but page does not redirect.

The file is here: http://www.screamingleather.com/maillist.html
Maybe there is another direction to go in altogether? I originally had the form set up with two buttons. One for join and the other for remove. They were both submit buttons and I was trying to find a way to send the user to a new page based on which button was clicked. Do you think this would be easier than what we are dealing with now?


Thanks for all this time and help. I greatly appreciate it.

-cmotor


<SCRIPT SRC="scripts/indexrefer.js" TYPE="text/javascript"></SCRIPT>
<script language="JavaScript">

var isChecked = false;
function isValidEmail(email) {
invalidChars = " /:,;"

if (email == "") { // cannot be empty
return false
}
for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters?
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf("@",1) // there must be one "@" symbol
if (atPos == -1) {
return false
}
if (email.indexOf("@",atPos+1) != -1) { // and only one "@" symbol
return false
}
periodPos = email.indexOf(".",atPos)
if (periodPos == -1) { // and at least one "." after the "@"
return false
}
if (periodPos+3 > email.length) { // must be at least 2 characters after the "."
return false
}
return true
}

function checkform() {

if (!isValidEmail(Fmaillist.email.value)) {
alert("Not a valid email address")
Fmaillist.email.focus()

}

else {
isChecked = document.Fmaillist.remove.checked; // returns true/false.
Fmaillist.submit();
setTimeout("nextPage()", 1000);
}
}


function nextPage(){
window.alert("nextPage called successfully");
document.location.href = (isChecked == true)
?"http://www.screamingleather.com/maillist_remove_confirm.html":"http://www.screamingleather.com/maillist_join_confirm.html";
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
</script>

SlankenOgen
07-05-2003, 10:35 AM
Try

else {
isChecked = document.Fmaillist.remove.checked;alert(isChecked);
}

and

<a href="#" onclick = "checkform();setTimeout('nextPage()',1000)">SUBMIT</a>

cmotor
07-05-2003, 11:52 AM
I tried the last suggestion you made and it was not working. I tried the code below, the form submitted and the page redirected to join confirm only. Maybe the syntax is not right?
What do you think is best now?
-cmotor


else {
Fmaillist.submit();
if (Fmaillist.remove.checked == true){
Fmaillist.redirect.value = "http://www.screamingleather.com/maillist_remove_confirm.html"
}
}


<Form name="Fmaillist" method="POST" action="/cgi-sys/FormMail.cgi">

<input type=hidden name="recipient" value="sales@screamingleather.com">

<input type=hidden name="redirect" value="http://www.screamingleather.com/maillist_join_confirm.html">

SlankenOgen
07-05-2003, 12:25 PM
When I tested the code I provided it worked fine. You should also use

document.Fmaillist.redirect.value

not

Fmaillist.redirect.value

ie. always preceed Fmaillist with document.

cmotor
07-05-2003, 12:31 PM
Hey, I got it to work. Here is the code.

Thanks for the help.
-cmotor

function checkform() {

if (!isValidEmail(Fmaillist.email.value)) {
alert("Not a valid email address")
Fmaillist.email.focus()
}

else {

if (Fmaillist.remove.checked == true){
Fmaillist.redirect.value = "http://www.screamingleather.com/maillist_remove_confirm.html"
}

else{Fmaillist.redirect.value = "http://www.screamingleather.com/maillist_join_confirm.html"
}

Fmaillist.submit();
}


<Form name="Fmaillist" method="POST" action="/cgi-sys/FormMail.cgi">

<input type=hidden name="recipient" value="sales@screamingleather.com">

<input type=hidden name="redirect" value="http://www.screamingleather.com/maillist_join_confirm.html">

SlankenOgen
07-05-2003, 12:59 PM
Well done!

But use document.Fmaillist...