Solved

window.location.href   -  doesn't refresh

Posted on 2001-07-02
19
649 Views
Last Modified: 2009-12-16
i have a little problem with page redirect, i used :   window.location.href
but it doesn't refresh the page.


this is a piece of my code. when the user change the combo box, i want to automatically
requery the page according to the selected combo box

-------------------------------------------------------

<% String byType = request.getParameter("BT");  %>

<select size="1"  name="slcType" onchange="FormRefresh()" >
     <option value="all">All</option>
     <option value="patient">patient</option>
     <option value="non patient">non patient</option>
</select>


<script language="JavaScript">
<!--
  function FormRefresh()
  {
     var frm = document.frmForm;    
     var intTemp = frm.slcType.selectedIndex;
         var slcVal = frm.slcType.options[intTemp].value;

     window.location.href = "membersListCodePlus.jsp?BT=" + slcVal;
     return true;
  }
//-->
</script>        
0
Comment
Question by:skyjamz
  • 4
  • 4
  • 3
  • +5
19 Comments
 
LVL 14

Expert Comment

by:puranik_p
ID: 6244609
have you tried...this?
window.location.href = window.location.href
0
 
LVL 14

Expert Comment

by:avner
ID: 6244728
skyjamz,
Your code is correct .
Are you getting any error ?
What version of browser are you using ?
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6244820
.href should mainly be used to check the current url...

Could you try the following:
location = "membersListCodePlus.jsp?BT=" + slcVal;
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6244824
To make your code some better:

<select size="1"  name="slcType" onchange="FormRefresh(this)" >
    <option value="all">All</option>
    <option value="patient">patient</option>
    <option value="non patient">non patient</option>
</select>


<script language="JavaScript">
<!--
 function FormRefresh(sObj)
 {
    var slcVal = escape(sObj[sObj.selectedIndex].value);

    window.location.href = "membersListCodePlus.jsp?BT=" + slcVal;
    return true;
 }
//-->
</script>        
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6244828
*sigh* in my last comment:

location = "membersListCodePlus.jsp?BT=" + slcVal;
0
 
LVL 14

Expert Comment

by:avner
ID: 6244841
CJ_S ,

Changing location.href or location shouldn't have any difference , and I've never saw a browser that treats the two properties differently.

0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6244857
Neither did I, and I didn't say that it should not work when using a certain property.

regards,
CJ
0
 
LVL 1

Expert Comment

by:poluru
ID: 6247650
hi,
after setting the location.href or after setting the document.forms[0].action="membersListCodePlus.jsp?BT="+slcVal;
   
better u submit the form.

document.forms[0].submit();
0
 

Author Comment

by:skyjamz
ID: 6248078
hi, sorry to keep you guys for waiting, because i'm really busy, but i really need this code to work properly, because i don't have many time left.

i have tried 'location' but it has the same result, when i change the value of combo box, it didn't requery the page, it showed the old query.


regards,
sky
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:alexcohn
ID: 6248491
If the old value and new value are identical, the browser can decide that nothing happened. It is recommended to use method

location.reload( [bReloadSource])

Parameters

bReloadSource Optional. Boolean that specifies one of the following possible values: false Default. Reloads the page from the browser cache.
true Reloads the page from the server.
 
or

location.replace(sURL)

Parameters

sURL Required. String that specifies the URL to insert into the session history.


0
 
LVL 14

Accepted Solution

by:
avner earned 100 total points
ID: 6248507
alexcohn ,
Since he is changing the url , the browser won't use the page from the cache , and in any way , the page will be loaded again ( from the web or from the cache) so he will need to see the change.

skyjamz ,

Try this sample code , and see if it works for you :

<select size="1"  name="slcType" onchange="FormRefresh(this)" >
    <option value="all">All</option>
    <option value="patient">patient</option>
    <option value="non patient">non patient</option>
</select>

<SCRIPT LANGUAGE="JavaScript">
<!--
function FormRefresh(obj)
{
self.location.href=self.location.href+"?"+obj.options.value
}
//-->
</SCRIPT>

0
 
LVL 3

Expert Comment

by:dapperry
ID: 6248959
Why don't you just use a form submit? You can have the page submit to itself. You can even change the action of the form based on what you have selected.

:) dapperry
0
 

Expert Comment

by:rogpereira
ID: 6249706

if you use IE try,


setTimeout( 'window.location.href="membersListCodePlus.jsp?BT="' + slcVal, 50 );
   
0
 

Expert Comment

by:rogpereira
ID: 6249715
the correct is:

setTimeout( 'window.location.href="membersListCodePlus.jsp?BT=' + slcVal + '"', 50 );
0
 

Author Comment

by:skyjamz
ID: 6251188
because i dont want to use setTimeout,
but i have found the solution.

but i appreciate for all of you help, and i decided to give the point to avner, because he makes my program more readability.

thanks,
sky
0
 
LVL 11

Expert Comment

by:alexcohn
ID: 6251585
what was the problem after all?
0
 

Author Comment

by:skyjamz
ID: 6255256
i have reject the answer, why my question still locked.
i dont want to use setTimeout.

the problem is i redirect the page to another page, so when i get back to the previous page, it still dont requery/refresh, but now i redirect to that page again, so it automatically refresh.

and now, can anyone tell me, can i set the browser properties like width, height, scroolbar and toolbar, when it opened. because i cannot use window.open command.

regards,
sky
0
 
LVL 14

Expert Comment

by:avner
ID: 6255487
Not when it is already opend.
0
 
LVL 11

Expert Comment

by:alexcohn
ID: 6256236
Yes you can set width, height, position. You cannot change toolbars, etc. You can play with scrolling, by using frames.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now