Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript go to next page...using HREF

Posted on 2003-03-25
10
Medium Priority
?
1,875 Views
Last Modified: 2010-07-27
I have a page where i want to hide the actual href link. when they click on the link (which is an image) i want the window/screen to move/go to another screen, but it's not working, the function is running but the pages doesn't change ... here is my code:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function gotonextpage(info) {
     nextscreenloc = ""
     var srtlocation = window.document.location.href;
     patharray = srtlocation.split("/")
     for (i = 0; i < (patharray.length-1); i++) {
         if (i > 0) nextscreenloc += "/"
         nextscreenloc += patharray[i]
     }
     nextscreenloc += "/wk7.asp"
     window.location.href = nextscreenloc;
}
//-->
</SCRIPT>
<META HTTP-EQUIV="Pragma" CONTENT="No-cache">
<META http-equiv="expires" content="-1">
</HEAD>
<BODY>
<a href="#" onclick="gotonextpage();"><img border="0" src="../images/viewandprint.jpg" ></a>
</BODY>
</HTML>
0
Comment
Question by:tomhoran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 4

Expert Comment

by:jonnal
ID: 8205693
hi
something like this ?


<HTML>
<HEAD>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function gotonextpage(info) {
    var nextscreenloc = "http://www.yoururl.com/dir1/dir2/etc/wk"
    window.location = nextscreenloc+info+'.asp';
}
//-->
</SCRIPT>
<META HTTP-EQUIV="Pragma" CONTENT="No-cache">
<META http-equiv="expires" content="-1">
</HEAD>
<BODY>
<a href="#" onclick="gotonextpage(7);"><img border="0" src="../images/viewandprint.jpg" ></a>
</BODY>
</HTML>
0
 

Author Comment

by:tomhoran
ID: 8205830
my code works to create a valid location string, it just doesn;t go to the next screen. i changed it from:

window.location.href = nextscreenloc;

to:

window.location = nextscreenloc;

based on your suggestion, but it still doesn't work??

0
 
LVL 4

Accepted Solution

by:
jonnal earned 300 total points
ID: 8205926
hi
return false missing eg

<a href="#" onclick="gotonextpage();return false">

0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:tomhoran
ID: 8205993
you got it...thanks!!
0
 

Author Comment

by:tomhoran
ID: 8206028
jonnal

one more quick question can i access passed parms from the first window. i'm using ASP so normally i would use:

testcheck = Request.QueryString("testcheck") to get the testcheck parm that was passed.

i need to pass this parm onto the next page to, so when i set the new location i need to pass the testcheck parm along. Thanks
0
 
LVL 4

Expert Comment

by:jonnal
ID: 8206590
hi again
you can use a query string
page below calls itself
and set the combo to the value in the query string when link is pressed

<head>
<title></title>
<script language="JavaScript">
<!--
var srcc="";

function getsrc(){
if(location.search != ""){
var stri = location.search.substring(1,location.search.length)
document.frm.TEMP.selectedIndex = parseInt(stri);
}
}

function setsrc(){
location = 'query.htm?'+srcc;
}

//  -->
</script>
</head>
<body body onload="getsrc()">

<form name="frm">
<select NAME="TEMP" onChange="srcc=this.selectedIndex">
<option value></option>
<option value="AAAAAA">AAAAAA</option>
<option value="BBBBBB">BBBBBB</option>
<option value="CCCCCC">CCCCCC</option>
<option value="DDDDDD">DDDDDD</option>
<option value="EEEEEE">EEEEEE</option>
</select>
</form>
<a href="query.htm" onclick="setsrc();return false">next</a>
</body>
</html>
0
 

Author Comment

by:tomhoran
ID: 8206680
thanks, not sure my question was straiget forward enough.

if i have a href like this on checkprint1.asp:

href=./checkprint2.asp?plainpaper=N

which creates a link on checkprint1.asp. When someone click on this link the window/screen will move from checkprint1.asp to window/screen checkprint2.asp.

what i want to know is when i am running the gotonextpage function (in checkprint2.asp) how can i figure out what value was passed in the  "plainpaper" parm. I know how to create hidden controls in a form (and how to acces the hidden control using javascript), but i don't want a form of the checkprint2.asp screen/window. What i need to know is how to get the "plainpaper" parm value.

thanks.
0
 
LVL 4

Expert Comment

by:jonnal
ID: 8212914
hi

href=./checkprint2.asp?plainpaper=N&pram2=yes&pram3=no

function getsrc(){
if(location.search != ""){
var stri = location.search.substring(1,location.search.length)
prams = stri.split('&')
for(i=0;i<prams.length;i++){
eval(prams[i]);
}
}
}

should make page variables
plainpaper with value = N
pram2 = "yes"
pram3 = "no"

and to send those vars to the new page just string build a query string


jonnal

0
 

Author Comment

by:tomhoran
ID: 8212998
Thank you thank you!!
0
 
LVL 4

Expert Comment

by:jonnal
ID: 8213093
cool
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question