/    Sign up×
Community /Pin to ProfileBookmark

Create a <Option> from another window

I am trying to populate a selectbox from another window that is open.
I can populate a textbox but i cant figure out the selectbox
This is what ive got w/ a error, the error occures on the line
that i try to populate the selectbox.

Test1.asp

[code]
<form name=form1 method=post>
<select name=”txtFiles”>
<option value=1>Test1</option>
<option value=2>Test2</option>
</select>
<input type=text name=txtAttachments value=””>
<a href=”Test2.asp” target=”_Blank();”>Open Window</a>
</form
[/code]

Test2.asp

[code]

<script language=javascript>
function AddOption(){
var i = window.opener.document.form1.txtFiles.options.length + 1;
alert(i);
window.opener.document.form1.txtAttachments.value=’Test Done’;
window.opener.document.form1.txtFiles.options[i] = new Option(‘asdfasdf’, i);
}
</script>
<form name=form method=post>
<input type=button name=cmdAdd value=”Add” Onclick=”AddOption();”>
</form>
[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@felgallMar 25.2005 — window.opener.document.form1.txtFiles.options.length + 1 is too big. The array starts from zero so the next empty spot is window.opener.document.form1.txtFiles.options.length (no +1 required).
Copy linkTweet thisAlerts:
@lmf232sauthorMar 25.2005 — dropped the + 1 and still a no go. Still get the javascript error.
Copy linkTweet thisAlerts:
@Warren86Mar 25.2005 — The function for inserting a new option must be in the main window.

<HTML>

<Head>

<Script Language=JavaScript>

var tmpWin = "";

function popWin(){

tmpWin = window.open('Temp.html',"")
window.opener = self;
}

function insertOpt(isData){

isList = document.forms.formcost.service;
isData = new Option(isData,isData);
isList.add(isData,isList.options.length);
}

function dispVal(isVal){

alert(isVal);
}


</Script>

</Head>

<Body>

<Form name='formcost'>

<Select name='service' onchange="dispVal(this.value)">

<option value='0' selected> Make a selection </option>

<option value='1' > Text 1 </option>

<option value='2' > Text 2 </option>

</Select>

</Form>

<input type=button value="Open Window" onclick="popWin()"><br><br>

</Body>

</HTML>

------------ Temp.html ---------------

<HTML>

<Head>

<Script Language=JavaScript>

function newOpt(){

opener.insertOpt("APple");
opener.insertOpt("PEar");
}


</Script>

</Head>

<Body>

<input type=button value="Add Options" onclick="newOpt()"><br><br>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@lmf232sauthorMar 25.2005 — Warren, beautiful.

I like how i can pass variables to a function in the main window.

Exaclty what i wanted.

Thanks.
Copy linkTweet thisAlerts:
@Warren86Mar 25.2005 — You're welcome. Take care.
×

Success!

Help @lmf232s spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...