By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,649 Members | 1,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,649 IT Pros & Developers. It's quick & easy.

How to prevent document.location from showing next page before redirect?

P: 24
Hi guys,
I was validating a field emp.
when condition is true it should display an alert and go to home page..
This is my code..

Expand|Select|Wrap|Line Numbers
  1. if (emp== "" || emp==null) {
  2.                     //response.sendRedirect("Home.jsp");
  3.  
  4.  
  5.             %>
  6.             <script>
  7.                 window.location="Home.jsp";
  8.                 alert("Employee Code is invalid");
  9.  
  10.             </script>
  11.             <%}%>
I used script to show alert to the user..
But if emp is valid it would go to Emp page..
Now when alert pops up I can see heading of Emp page (only heading and logo) along with the alert and then it goes to Home page..

How do I prevent it from showing the Emp page alongwith the alert message...
May 30 '13 #1

✓ answered by Oralloy

Shepard,

Think about the sequence of events:
  1. User displays your data entry page.
  2. User enters various data.
  3. User clicks "ok", or whatever the submit button is.
  4. The browser transfers to the "Emp" page, sending all the form fields to your server.
  5. The "Emp" PHP page processes, finds a problem, and then sends your JavaScript that forwards to the "Home" page.
  6. The browser recieves the dynamically generated "Emp" page, with the JavaScript
  7. The browser executes the script, and transfers to the "Home" page.

Now, think about how you want things to really happen.

Some of the options you might try are:
  1. Auto forwarding.
  2. Let the EMP page generate the error message and redisplay the form.
  3. Use an intermediate processing step in place of the EMP page, which then auto-forwards to EMP or HOME, depending on the result.

Luck!
Oralloy

Share this Question
Share on Google+
2 Replies


Oralloy
Expert 100+
P: 983
Shepard,

Think about the sequence of events:
  1. User displays your data entry page.
  2. User enters various data.
  3. User clicks "ok", or whatever the submit button is.
  4. The browser transfers to the "Emp" page, sending all the form fields to your server.
  5. The "Emp" PHP page processes, finds a problem, and then sends your JavaScript that forwards to the "Home" page.
  6. The browser recieves the dynamically generated "Emp" page, with the JavaScript
  7. The browser executes the script, and transfers to the "Home" page.

Now, think about how you want things to really happen.

Some of the options you might try are:
  1. Auto forwarding.
  2. Let the EMP page generate the error message and redisplay the form.
  3. Use an intermediate processing step in place of the EMP page, which then auto-forwards to EMP or HOME, depending on the result.

Luck!
Oralloy
May 30 '13 #2

P: 24
Thanks Oralloy!
I followed the steps and found that my logic
Expand|Select|Wrap|Line Numbers
  1. if (emp== "" || emp==null) { 
  2.  
executes only after header info of Emp page executes..So it was displaying Heading of the page and then reached the logic...
Now I modified it to reach logic first and then heading...
Thanks again... problem solved!!!
Jun 1 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.