Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect script if specific id and database field then redirect 1

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

I am by no means a programmer, but I was able to build a small JavaScript that redirects users to a link depending on their name. this works well.

I need to add a condition to my script but not sure how to go about it.

This is what my script looks like

JavaScript:
<script language="JavaScript">

temp= window.prompt ("Please Type Your Name" , "");
if (temp=="") { window.location="[URL unfurl="true"]http://mywebsite/rma1/redirect.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>";}


else if (temp=="Shu"|| temp=="shu"|| temp=="SHU"|| temp=="SShah" || temp=="Justin"|| temp=="JUSTIN"|| temp=="justin"|| temp=="JThomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME" || temp=="piotr" ||temp=="PIOTR")  { window.location="[URL unfurl="true"]http://mywebsite/rma1/editquality.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

else if (temp=="Kim"|| temp=="kim"|| temp=="mike"|| temp=="Mike"|| temp=="MIKE"|| temp=="barb"|| temp=="Kimberligh")  { window.location="[URL unfurl="true"]http://mywebsite/rma1/editcredit.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

else if (temp=="George"|| temp=="george"|| temp=="veronica"|| temp=="Veronica"|| temp=="VERONICA"|| temp=="Cindy"|| temp=="GEORGE"|| temp=="JESS"|| temp=="jessica"|| temp=="Jessica"|| temp=="jess"|| temp=="Jess"|| temp=="Kevin"|| temp=="kevin"|| temp=="Shu"|| temp=="shu"|| temp=="Sue"|| temp=="tina"|| temp=="Tina"|| temp=="TINA"|| temp=="sue"|| temp=="Justin"|| temp=="JUSTIN" || temp=="JTomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME" || temp=="Piotr" || temp=="piotr" ||temp=="PIOTR" || temp=="cynthia" || temp=="CYNTHIA" ||temp=="Cynthia")  { window.location="[URL unfurl="true"]http://mywebsite/rma1/editcustserv.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}
</script>

so what I am looking to do is
Code:
else if (temp=="Shu"|| temp=="shu"|| temp=="SHU"|| temp=="SShah" || temp=="Justin"|| temp=="JUSTIN"|| temp=="justin"|| temp=="JThomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME" || temp=="piotr" ||temp=="PIOTR") [highlight #FCE94F]and database field frmtype = credit then redirect to[/highlight] { window.location="[URL unfurl="true"]http://mywebsite/rma1/editquality.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

Not sure how to add the highlighted part

I think I could do a variable?

Code:
var S=document.form.frmtype.value;
and insert it where the highlighted code is ??

any suggestions are more than welcome!!


Thanks


EV
 
How is that database field getting to the page?

Are you storing it in a form field?

If so, then yes, you can get it into a variable as you show and add that requirement to your conditional statement.

If not then it would depends on how that value is coming in.





----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
vacunita,

Yes it is being stored in a form field.

the part that I am a bit confused is how to actually I implement it

would it be something like this?
Code:
var S=document.form.frmtype.value; 

else if [highlight #FCE94F]([/highlight](temp=="Shu"|| temp=="shu"|| temp=="SHU"|| temp=="SShah" || temp=="Justin"|| temp=="JUSTIN"|| temp=="justin"|| temp=="JThomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME" || temp=="piotr" ||temp=="PIOTR")[highlight #FCE94F] and S="credit")[/highlight] { window.location="[URL unfurl="true"]http://webdav/rma1/editquality.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}
 
The comparison should be with && not "and" just like your previous comparisons use || not "or". and you need double equal signs for the comparison. ==


So:

Code:
else if ((temp=="Shu"|| temp=="shu"|| temp=="SHU"|| temp=="SShah" || temp=="Justin"|| temp=="JUSTIN"|| temp=="justin"|| temp=="JThomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME" || temp=="piotr" ||temp=="PIOTR") [b][COLOR=#A40000]&&[/color][/b] S[b][COLOR=#A40000]==[/color][/b]"credit") {...}

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
vacunita,

makes sense, I understand it.

I appreciate it thank you!!!!
 
vacunita,

I tried that but not much luck,

the part of the script that asks for the user name does not show up, it goes straight to the deny page, because there is no user name

this is the begginging of the script
JavaScript:
temp= window.prompt ("Please Type Your Name" , "");
if (temp=="") { window.location="[URL unfurl="true"]http://mywebsite/rma1/redirect.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>";}

no idea why
 
Not quite sure I understand, Your condition there checks to see if temp is an empty string =="" . If it is an empty string, it will redirect to = Cdbl((rsGuestbook("ID")))%>
Otherwise it will continue on.

What exactly is not working?

How are you calling this?



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
so I have the script (scroll right to see the other highlighted code)

Code:
<script language="JavaScript">



temp= window.prompt ("Please Type Your Name" , "");
if (temp=="") { window.location="[URL unfurl="true"]http://webdav/rma1/redirect.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>";}


else if (temp=="Shu"|| temp=="shu"|| temp=="SHU"|| temp=="SShah" || temp=="Justin"|| temp=="JUSTIN"|| temp=="justin"|| temp=="JThomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME" || temp=="piotr" ||temp=="PIOTR" ||temp=="Piotr")  { window.location="[URL unfurl="true"]http://webdav/rma1/editqualityreturns.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

else if (temp=="Kim"|| temp=="kim"|| temp=="mike"|| temp=="Mike"|| temp=="MIKE"|| temp=="barb"|| temp=="Kimberligh")  { window.location="[URL unfurl="true"]http://webdav/rma1/editcredit.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

else if (temp=="George"|| temp=="george"|| temp=="veronica"|| temp=="Veronica"|| temp=="VERONICA"|| temp=="Cindy"|| temp=="GEORGE"|| temp=="JESS"|| temp=="jessica"|| temp=="Jessica"|| temp=="jess"|| temp=="Jess"|| temp=="Kevin"|| temp=="kevin"|| temp=="Shu"|| temp=="shu"|| temp=="Sue"|| temp=="tina"|| temp=="Tina"|| temp=="TINA"|| temp=="sue"|| temp=="Justin"|| temp=="JUSTIN" || temp=="JTomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME"  || temp=="cynthia" || temp=="CYNTHIA" ||temp=="Cynthia") && (rmat=="Credit") { window.location="[URL unfurl="true"]http://webdav/rma1/editcustservreturnscredit.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

else if ((temp=="George"|| temp=="george"|| temp=="veronica"|| temp=="Veronica"|| temp=="VERONICA"|| temp=="Cindy"|| temp=="GEORGE"|| temp=="JESS"|| temp=="jessica"|| temp=="Jessica"|| temp=="jess"|| temp=="Jess"|| temp=="Kevin"|| temp=="kevin"|| temp=="Shu"|| temp=="shu"|| temp=="Sue"|| temp=="tina"|| temp=="Tina"|| temp=="TINA"|| temp=="sue"|| temp=="Justin"|| temp=="JUSTIN" || temp=="JTomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME"  || temp=="cynthia" || temp=="CYNTHIA" ||temp=="Cynthia"))[highlight #FCE94F] && (rmat=="Return")[/highlight] { window.location="[URL unfurl="true"]http://webdav/rma1/editcustservreturns.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>&" + "temp=" + temp;}

</script>
<script>
function initialize()
{
 document.forms['form'].elements['csupdatedby'].value = temp ;
  [highlight #FCE94F]document.forms['form'].elements['rmatype'].value = rmat ;[/highlight]
}
</script>
I added the hightlighted code but by adding that it bypasses the
Code:
temp= window.prompt ("Please Type Your Name" , "");
and goes directly to
Code:
if (temp=="") { window.location="[URL unfurl="true"]http://webdav/rma1/redirect.asp?id=<%[/URL] = Cdbl((rsGuestbook("ID")))%>";}
 
The problem is with your conditionals. All Conditions should be surrounded by () for the entire condition. You are putting parts of your conditions outside the () of each else if statement.

This causes the JS to error out, and simply not run, which means your page simply loads as is.


Try:

Code:
else if [highlight #C17D11][b][COLOR=#FCE94F]([/color][/b][/highlight](temp=="George"|| temp=="george"|| temp=="veronica"|| temp=="Veronica"|| temp=="VERONICA"|| temp=="Cindy"|| temp=="GEORGE"|| temp=="JESS"|| temp=="jessica"|| temp=="Jessica"|| temp=="jess"|| temp=="Jess"|| temp=="Kevin"|| temp=="kevin"|| temp=="Shu"|| temp=="shu"|| temp=="Sue"|| temp=="tina"|| temp=="Tina"|| temp=="TINA"|| temp=="sue"|| temp=="Justin"|| temp=="JUSTIN" || temp=="JTomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME"  || temp=="cynthia" || temp=="CYNTHIA" ||temp=="Cynthia") && (rmat=="Credit")[highlight #C17D11][b][COLOR=#FCE94F])[/color][/b][/highlight]

and

Code:
else if [highlight #C17D11][b][COLOR=#FCE94F]([/color][/b][/highlight](temp=="George"|| temp=="george"|| temp=="veronica"|| temp=="Veronica"|| temp=="VERONICA"|| temp=="Cindy"|| temp=="GEORGE"|| temp=="JESS"|| temp=="jessica"|| temp=="Jessica"|| temp=="jess"|| temp=="Jess"|| temp=="Kevin"|| temp=="kevin"|| temp=="Shu"|| temp=="shu"|| temp=="Sue"|| temp=="tina"|| temp=="Tina"|| temp=="TINA"|| temp=="sue"|| temp=="Justin"|| temp=="JUSTIN" || temp=="JTomas" || temp=="Jaime" || temp=="jaime" ||temp=="JAIME"  || temp=="cynthia" || temp=="CYNTHIA" ||temp=="Cynthia") && (rmat=="Return")[highlight #C17D11][b][COLOR=#FCE94F])[/color][/b][/highlight]

When using Js use your Browser's JS Console to check for JS errors. Its important to keep an eye on the console closely as you code.

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top