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 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Detroit
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    new options in new window

    In the script below I open a window and populate a select object. It works in Mozilla, but not in IE. IE claims that the select object in the new window is not an object. However, I am able to retrieve properties from it such as length. Any suggestions?

    function GetCodes() {
    var form = document.forms[0];
    var itemObj = form.item;

    // figure out which item has been selected
    var selected_item=""
    for (var i = 0; i < itemObj.length; i++) {
    if ( itemObj.options[i].selected ) {
    selected_item = itemObj.options[i].value
    // alert(itemObj.options[i].value)
    }
    }

    // open new window and build simple form
    var newWindow = window.open("","EnterValue","status,menubar,height=400,width=400")
    var content = "<html><head></head><body><form><select name='codes' size=1></select><br><input type=button value='OK' onclick='self.close()'></input></form></body></html>"
    newWindow.document.write(content)

    // build option list in new window
    var codesObj = newWindow.document.forms[0].codes;
    var result = ""
    var item_array = all_items[selected_item]
    for (var j in item_array) {
    codesObj.options[codesObj.length] = new Option(item_array[j], j);
    }

    newWindow.document.close()
    }

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    After this line:

    newWindow.document.write(content)

    add:

    newWindow.document.close()

    then remove it from the other location and see if that helps things.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Not really gonna help the problem but this bit of code

    Code:
    // figure out which item has been selected
    var selected_item=""
    for (var i = 0; i < itemObj.length; i++) {
        if ( itemObj.options[i].selected ) {
        selected_item = itemObj.options[i].value
        // alert(itemObj.options[i].value)
        }
    }
    can be replace with:
    Code:
    var selected_item = itemObj.options[itemObj.selectedIndex].value

  • #4
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Detroit
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Roy! I haven't had a chance to get back to this, but I didn't want you to think that your response was unappreciated. I'll let you know how it goes.

    Also, thanks for the code review hharchester! I always value a better more effiecient way of handling a task.

  • #5
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Detroit
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your suggestion Roy, but it didn't work.

    Anyone else have a suggestion?

    This is killing me because it works great in Mozilla as is!

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you post url or attach a sample page showing the problem (simplify it to just enough to show the problem if you can)?
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #7
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    IE has occasional synchronicity problems (like the Police); this might or might not help:
    Code:
    // open new window and build simple form
    content = '<html><head></head><body><form><select name="codes" size="1"></select><br><input type="button" value="OK" onclick="self.close()"></form></body></html>';
    newWindow = window.open('javascript&#58;opener.content','EnterValue','status,menubar,height=400,width=400');
    Make sure content is global (newWindow should be too). The window opening code should be all on one line (with no space after the dot). This board does that...

  • #8
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Detroit
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks cheese still no luck.

    Roy, here's the URL:

    http://www.jamcrackermusic.com/cgi-b...uery_NewWin.pl

    Click the "?" button. Use Mozilla to see what the new window is supposed to look like, then try IE to see my problem:

    Let me know what you think, and thanks!

  • #9
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whew...IE has encountered a problem and will go bye-bye...can't see that often enough.

    Sorry...didn't quite explain: loading the 'document' with a javascript&#58; url eliminates the need for any document.open/write/writeln/close statements. Just like loading a file. This:

    window.open('javascript&#58;opener.content',.....

    ...does this:

    newWindow.document.open();
    newWindow.document.write(content);
    newWindow.document.close();

  • #10
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Detroit
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheese,

    Okay, I think I understand now. However, after I load the page I am attempting to modify the options. I guess that argues that I build the options within the content var, but I had trouble with the interpreter/compiler reading the text within the var.

    Or, am I still missing your point?

  • #11
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Had some real problems - related to scope - in calling the Option() constructor from another window. JS functions are lexically scoped, so scripting from one window to another isn't always successful. Tried DOM - finally gave up, and did it the easy way:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html
    	PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
    	"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>Untitled Document</title>
    <script type="text/javascript" language="JavaScript">
    <!-- Hide script
    
    all_items = new Array()
    q1 = new Array()
    q1["1"]="Very Dissatisfied"
    q1["2"]="Somewhat Dissatisfied"
    q1["3"]="Neutral"
    q1["4"]="Somewhat Satisfied"
    q1["5"]="Very Satisfied"
    q1["6"]="Don't Know"
    q1["7"]="Refused/NA"
    all_items["q1"]=q1
    q2 = new Array()
    q2["1"]="Very Unlikely"
    q2["2"]="Somewhat Unlikely"
    q2["3"]="Neutral"
    q2["4"]="Somewhat Likely"
    q2["5"]="Very Likely"
    q2["6"]="Don't Know"
    q2["7"]="Refused/NA"
    all_items["q2"]=q2
    q3 = new Array()
    q3["0"]="0"
    q3["1"]="1"
    q3["2"]="2"
    q3["3"]="3"
    q3["4"]="4"
    q3["5"]="5"
    q3["6"]="6"
    q3["7"]="7"
    q3["8"]="8"
    q3["9"]="9"
    q3["10"]="10"
    q3["11"]="More than 10"
    q3["12"]="Don't know"
    q3["13"]="Refused/NA"
    all_items["q3"]=q3
    
    
    function ItemLabels() {
     	var form = document.forms[0];
    	var itemObj = form.item;
    	var valueObj = form.value;
    
    	// clear the current value list
    	valueObj.options.length=0
    
    	// figure out which item has been selected
    	var selected_item = itemObj.options[itemObj.selectedIndex].value
    
    	// build new option list
    	var result = ""
    	var item_array = all_items[selected_item]
    	for (var j in item_array) {
    		valueObj.options[valueObj.length] = new Option(item_array[j], j);
    	}
    }
    
    var newWindow = null;
    var content;
    
    function GetCodes(itemObj) {
         if (newWindow && !newWindow.closed) 
             newWindow.close();
         var selected_value = itemObj.options[itemObj.selectedIndex].value;
         var item_array = all_items[selected_value];
         content = '';
         content += '<html><head></head><body><form><select name="codes" size="1">';
         for (var j in item_array) 
              content += '<option value="' + j + '">' + item_array[j] + '</option>';
         content += '</select><input type="button" value="OK" onclick="self.close()"></form></body></html>'
         newWindow = window.open('javascript&#58;opener.content','EnterValue','status,menubar,height=400,width=400');
         if (newWindow && !newWindow.closed) 
             newWindow.focus();
         return true;
    }
    
    </script>
    </head><body><form method="post" action="/cgi-bin/build_query_NewWin.pl" enctype="application/x-www-form-urlencoded">
    <table border="1"><tr><th>Field</th> <th>Operator</th> <th>Value</th></tr> <tr><td>
    <select name="item" size="1">
    <option  value="q1">How satsified</option>
    <option  value="q2">How likely?</option>
    <option  value="q3">How many times?</option>
    <option  value="q4">Name</option>
    </select></td> <td><select name="operator" size="1">
    <option  value="&lt;=">less than/equal to</option>
    <option  value="&gt;=">greater than/equal to</option>
    <option  value="&lt;">less than</option>
    <option selected value="=">exactly equal to</option>
    <option  value="like">like</option>
    <option  value="&gt;">greater than</option>
    <option  value="in">in list</option>
    </select>
    </td>
    <td><input type="text" name="value"  size="50" />
    <input type="button" name="?" value="?" onclick="return GetCodes(item)" />
    </td></tr></table><br />
    <input type="submit" name=".submit" />
    <input type="hidden" name=".cgifields" value="operator" />
    <input type="hidden" name=".cgifields" value="item" />
    </form></body></html>
    Not quite sure about the rest of it...don't forget to clean up after the editor.

  • #12
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Detroit
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Cheese,

    It works! (Of course, you knew that.) Thanks so much! I really appreciate your time and effort. Now, maybe I can abandon my other ideas of using CSS invisibility and/or frames to do this same kind of thing.

    Thanks again! You rock!



    Greg


  •  

    Posting Permissions

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