...

View Full Version : new options in new window



gregality
07-08-2003, 08:11 PM
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()
}

Roy Sinclair
07-08-2003, 09:19 PM
After this line:

newWindow.document.write(content)

add:

newWindow.document.close()

then remove it from the other location and see if that helps things.

ellisd5
07-09-2003, 05:21 PM
Not really gonna help the problem but this bit of 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:


var selected_item = itemObj.options[itemObj.selectedIndex].value

gregality
07-10-2003, 05:00 PM
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.

gregality
07-29-2003, 07:39 PM
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!

Roy Sinclair
07-29-2003, 08:00 PM
Can you post url or attach a sample page showing the problem (simplify it to just enough to show the problem if you can)?

cheesebagpipe
07-29-2003, 08:02 PM
IE has occasional synchronicity problems (like the Police); this might or might not help:


// 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 :mad: does that...

gregality
07-29-2003, 08:31 PM
Thanks cheese still no luck.

Roy, here's the URL:

http://www.jamcrackermusic.com/cgi-bin/build_query_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!

cheesebagpipe
07-29-2003, 08:53 PM
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();

gregality
07-29-2003, 09:14 PM
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?

cheesebagpipe
07-29-2003, 10:11 PM
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:


<?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.

gregality
07-29-2003, 10:47 PM
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!

:thumbsup:

Greg



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum