Solved

window.location.href   -  doesn't refresh

Posted on 2001-07-02
19
676 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
[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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
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…

690 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