Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window opening controls pain

    my javascript, in a src'd file:
    Code:
    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:
    Code:
    <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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

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

    Code:
    <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" />

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •