Jump to content

Is it possible for javascript on a page to prevent header redirect ?


lonewolf217

Recommended Posts

I am having an issue on one of my pages where my header redirect isn't working, and have scoured the page to find out where I may be outputting something before I redirect and I cannot find anything.  The bulk of the changes I have made recently have been adding more javascript onto the page so I cannot figure out what the error could be besides that.  Also, for some reason, the error gives an error on a line that is smack in the middle of the javascript in the head of the document which I just cannot understand.

 

Any ideas on the theory of the question without having to post way too much code ?

it seems to be an issue with this javascript function. as soon as I remove it, redirect works fine.  I actually have to delete the function though, just commenting it out doesn't seem to help which is wierd

 

		function selectSpecificProduct(x) {
			switch(x) {
				case 'Exchange':
					document.getElementById('exproduct').style.display='';
					document.getElementById('sppproduct').style.display='none';
					document.getElementById('nasproduct').style.display='none';
					document.getElementById('commonproduct').style.display='none';
					break;
				case 'Sharepoint':
					document.getElementById('exproduct').style.display='none';
					document.getElementById('sppproduct').style.display='';
					document.getElementById('nasproduct').style.display='none';
					document.getElementById('commonproduct').style.display='none';				
					break;
				case 'NAS':
					document.getElementById('exproduct').style.display='none';
					document.getElementById('sppproduct').style.display='none';
					document.getElementById('nasproduct').style.display='';
					document.getElementById('commonproduct').style.display='none';					
					break;
				case 'Common':
					document.getElementById('exproduct').style.display='none';
					document.getElementById('sppproduct').style.display='none';
					document.getElementById('nasproduct').style.display='none';
					document.getElementById('commonproduct').style.display='';					
					break;
				default:
					document.getElementById('exproduct').style.display='none';
					document.getElementById('sppproduct').style.display='none';
					document.getElementById('nasproduct').style.display='none';
					document.getElementById('commonproduct').style.display='none';	
					break;
				}
		}

 

error message:

[02-May-2009 08:54:52] PHP Warning:  Cannot modify header information - headers already sent by (output started at page.php:135) in page.php on line 243

 

line 135 is three lines down in the function.  243 is where i redirect

I think you have the function declaration in the wrong place, ie before the headers are sent.

Javascript is client side, anything client side needs to be in the code AFTER the headers are sent.

see also

http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

 

all of my javascript functions are in the <head> portion of the document .  I have the several functions before this one.

 

all of them are before any PHP code is started, but when my validation script comes here, shouldn't it process the PHP validation and redirect before sending any javascript to the client ?

 

I have read the sticky, many times

Please show us the PHP that comes before this section of your code.

 

My best guess is that you have an unterminated string in your PHP code that starts with a single quote. The single quote that starts the case statement is terminating that string and the rest of the case string is output to the browser. The reason commenting the code out doesn't work is that the single quote is still there and the PHP interpreter is looking for it.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.