/    Sign up×
Community /Pin to ProfileBookmark

Select Box selectedIndex Problem

Hi all,

I have the following code which populates Box2 with values dependant on the option selected in box1. e.g. if user selects “USD” in box1 then box2 populated with “HKD”, “EUR”, if user selects “GBP” in box1 then box2 populated with “IDO”, “AUD”…Code is as follows:

[CODE]function setOptions(o){
var ccy2 = document.predealform.ccy2;
ccy2.options.length = 0;
if (o == “USD”){
ccy2.options[ccy2.options.length] = new Option(‘HKD’);
ccy2.options[ccy2.options.length] = new Option(‘EUR’);}
if (o == “GBP”){
ccy2.options[ccy2.options.length] = new Option(‘IDO’);
ccy2.options[ccy2.options.length] = new Option(‘AUD’);}
}[/CODE]

Once this code has run the user submits the form. What I need is to repopulate box1 and box2 with the values submitted, for it to be remembered.
I rerun the above function so box1 & box2 represent values allowed. It seems to reload and show value selected in box1 & box2 populates with correct values (dependant on box1 selected) but the box2 value shows the first option created using new Option(“”) rather than the one selected.

I do have access to the var which represents the box2 option selected so what I need is a way of creating a new Option which is equivalent to the value of box2 selected…

Any help much appreciated,

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jvanamaliDec 15.2005 — you should dynamically select the ccy2 option using selected index

for example if you have the option selected in ccy2s then

var si; //selected index

if (ccy2s=='EUR' || ccy2s=='AUD'){

si=1;

} else {

si=0;

}

ccy2.selectedIndex=si;

hope this will solve your problem
×

Success!

Help @johrik 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.27,
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,
)...