/    Sign up×
Community /Pin to ProfileBookmark

Hi, I created a couple of arrays to store some values.Based on a value selected from ccy select box, I want to populate the corresponding
array into the stgy select box.If I choose another value from ccy select box, I want to be able to remove the
existing value from the stgy select box and populate the second array into it.
This code is not working.Please help me.

Thanks,

<HTML><BODY>

<FORM Name=”Test”>
<SELECT Name=”ccy” onChange=”fillstgy();”>

<option value=”1″>TKY</option>
<option value=”2″>EUR</option>
<option value=”3″>AUD</option>
<option value=”4″>USD</option>

</SELECT>
<SELECT Name=”stgy” >
<option value=”1″>select</option>

</SELECT>

</FORM>

<SCRIPT>

var stgyTKY=new Array();
stgyTKY[0]=”TKY1″;
stgyTKY[1]=”TKY2″;
stgyTKY[2]=”TKY3″;

var stgyEUR=new Array();
stgyEUR[0]=”EUR1″;
stgyEUR[1]=”EUR2″;
stgyEUR[2]=”EUR3″;

var frm = document.Test;

// fill a select from contents of an array!
function fill( sel, ar )
{
var ix;
for ( ix = sel.options.length-1; ix >= 0; –ix )
sel.options[ix] = null;
alert(“removing elements”);
for ( ix = 0; ix < ar.length; ++ix )
sel.options[ix] = new Option( ar[ix][0], ar[ix][1] );
alert(“adding elements”);
}

function fillstgy()
{
if(document.forms[0].ccy.selectedIndex == 0)
{
alert(“JPY”);
TKY = stgyTKY;
fill( frm.stgy, TKY );
}
else if(document.forms[0].ccy.selectedIndex == 1)
{
alert(“EUR”);
EUR = stgyEUR
fill( frm.stgy, EUR );
}
}

</SCRIPT>

</BODY></HTML>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@fredmvDec 13.2003 — [i]Originally posted by mili [/i]

[B]This code is not working.[/B][/QUOTE]
Simply saying it's "not working" can mean a lot of different things. What [i]exactly[/i] isn't it doing that it should be?
Copy linkTweet thisAlerts:
@miliauthorDec 13.2003 — It is wiping out the option values from the existing select box, but not populating the values from array
Copy linkTweet thisAlerts:
@fredmvDec 13.2003 — Do you want it to append options to the other select box as opposed to erasing existing values then adding more options? If not, please clarify.
Copy linkTweet thisAlerts:
@miliauthorDec 14.2003 — I'm sorry if I did not communicate well.

Here is my problem:

  • 1. The default for ccy list box is "TKY". So I want to load only the options from "stgyTKY" array into stgy list box.

  • 2. When I fire an onchange event on ccy list box, let's say I choose EUR from ccy list box this time, I want to wipe out all the "stgyTKY" options from the stgy list box and load only the options from "stgyEUR" array.


  • Thanks
    ×

    Success!

    Help @mili 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.25,
    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,
    )...