View Single Post
Old 03-13-2013, 09:05 PM   PM User | #1
Max31
New to the CF scene

 
Join Date: Mar 2013
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Max31 is an unknown quantity at this point
Unhappy 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() {
   var answer = confirm("Are you sure")
   if (answer){
     window.location = "www.google.com";
   }else{
     window.location = "www.facebook.com";
   }
 }
I also have a form that calls js a function called Validate() which then calls the redirect() function if the statements are true - this all works apart from the redirection of pages.

Code:
function Validate() {
    
    var value = readCookie('TestCookie');

    if ( value == 1 && document.validate.drugid.selectedIndex == 5 )
    {
		redirect();   
   
   }

Below is my form:

Code:
<form name="validate" action="<?php echo $pfile;?>" onsubmit="return Validate()" method="post">
<input type="hidden" name="patientid" id="drugnames" value="<?php echo $patientid;?>" />

<?php
  
	//blah blah blah
?>

<br><br><input name="submit" id="formbutton"  type="submit" value="Prescribe"/>
</form>

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.
Max31 is offline   Reply With Quote