...

View Full Version : window opening controls pain



Choopernickel
04-10-2003, 07:55 PM
my javascript, in a src'd file:


var targetWindow = "trextras";
function oneNewWindow() {
targetWindow = "trextras";
document.multirecords.target = targetWindow;
document.multirecords.oneNewWindow.checked = true;
}

function manyNewWindows() {
targetWindow = "_blank";
document.multirecords.target = targetWindow;
document.multirecords.manyNewWindows.checked = true;
}

my html:


<input type="Radio" id="oneNewWindow" onclick="oneNewWindow()" />
<img src="img/oneNew.gif" title="Open all new pages in the same window"
onclick="oneNewWindow()" style="cursor:pointer" />
<input type="Radio" id="manyNewWindows" onclick="manyNewWindows()" />
<img src="img/allNew.gif" title="Open each new page in its own new window"
onclick="manyNewWindows()" style="cursor:pointer" />


I trigger the oneNewWindow() function with a <script> element later in the HTML, and it runs and there's no problem.

Shizzle don't want to work onclick (onclizzle?): IE gives me the ever-so-popular "Object doesn't support this property or method" error. How? It's already run once. I know the functions are good. What am I missing?

Any thoughts? Thanks in advance.

Roy Sinclair
04-10-2003, 08:40 PM
You are using the same name for an object on the page and as a function. That's going to lead to confusion to both you and the browser. You also don't need to set the radio buttons to true, let the browser take care of that. It also appears that the targetWindow global variable doesn't serve much purpose either and could easily be eliminated, lastly functions called by an event should be coded and called to return true to process the event or return false to cancel the event:



function oneNewWindow() {
document.multirecords.target = "trextras";
return true;
}

function manyNewWindows() {
document.multirecords.target = "_blank";
return true;
}






<input type="Radio" name="howmanywindows onclick="return oneNewWindow()" />
<img src="img/oneNew.gif" title="Open all new pages in the same window"
onclick="return oneNewWindow()" style="cursor: pointer" />
<input type="Radio" name="howmanywindows" onclick="return manyNewWindows()" />
<img src="img/allNew.gif" title="Open each new page in its own new window"
onclick="return manyNewWindows()" style="cursor: pointer" />

Choopernickel
04-10-2003, 09:08 PM
Originally posted by Roy Sinclair
You are using the same name for an object on the page and as a function. That's going to lead to confusion to both you and the browser.

Excellent point - thanks.


Originally posted by Roy Sinclair
You also don't need to set the radio buttons to true, let the browser take care of that.

Actually, I have to set it if they click one of the images that is also enabled with the function.


Originally posted by Roy Sinclair
It also appears that the targetWindow global variable doesn't serve much purpose either and could easily be eliminated

It's used by another couple of functions, each of which use window.open(someURL, targetWindow, 'attributes...'), and I can't get rid of it.


Originally posted by Roy Sinclair
lastly functions called by an event should be coded and called to return true to process the event or return false to cancel the event

I was under the impression that without onEvent="return function()" it really didn't matter.


Thanks for your remarks, Roy. I've changed the radio buttons' names and script references, and now it's all working! I really should have known better about those unique names.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum