![]() |
Redirection of Javascript failing
Hi,
I am new to JavaScript and i though i had the hang of it until now, i apologise if this is an easy fix. Below is my js function: Code:
function redirect() {Code:
function Validate() {Below is my form: Code:
<form name="validate" action="<?php echo $pfile;?>" onsubmit="return Validate()" method="post">The problem is my window.location are not redirecting at all, they just clear most of the contents of my page. Does anyone have any ideas how to solve this? I think it may have something to do with the "type=submit" on my form,it may have to be "button" but when i change this, i cant submit the page. Any help would be greatly appreciated. |
Code:
function redirect() { |
It's the type="submit", but only indirectly.
The real problem is your Validate() function. You *DO* correctly code return Validate() in the <form> tag, but then you never do a return false from that function! When you don't return any particular value from Validate(), you have ONLY a 1 in 4 billion chance that the form will *not* submit, or in other words near certainty that it will. So you need: Code:
function Validate() { |
Hey man, thanks for taking the time to reply, but unfortunately i had tried that before with no success :(
|
Sorry...forgot to say: That <form> submittal is, effectively, overriding your change of location. So you indeed and up submitting the <form> and, since it looks like the action= is this same page, the server then serves up a new copy of the page.
|
Ah i see now, but surely if i want to redirect dependant on user inputs, should this be dismissed completely? I don't think this would work if i take it out all together though
|
I'm sorry i didnt see you earlier post about the return false statement! It worked thank you so much!
|
| All times are GMT +1. The time now is 07:36 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.