Not a Member Yet,
Click here to Register

ID: 492
Viewed: 4430
Added: Sep 25, 2002
Version: 1
Snippet uploaded by: snippet
Written By: kdjoergensen
Demo: Sorry, no demo



User Rated at: 5 Stars5 Stars5 Stars5 Stars5 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

This little sciprt makes it so you can have the user select which currency is appropriate for their country.

very easy to setup and run.

Browsers: IE5+

<!---Head--->
// can go in between the body tags also

<script language="javascript">
<!--

// the set function will populate the select element when called
function set(curr,form){

// two arrays are created: one for USD and one for EUR. The first
//line is for text (what is visible to the user0 the 2nd line is the
//value component */

var rangeUSD = {
txt : ["choose US Computer","<$2000","$2001-$5000",">$5000"],
val : ["#", "lowD","mediumD","highD"]
};

var rangeEUR = {
txt : ["choose Eur Computer", "<e1800","e1801-e4000",">e4000","e2002"],
val : ["#", "lowE","mediumE","highE","specialE"]
};


// get ready to make our selection
var useCurrency = new Array();

// if the selected radio element (captured in the variable "curr")
// has a value of "usd" then we set our useCurrency array equal to
// the rangeUSD array defined above. Otherwise use the rangeEur array.

if (curr.value == "usd"){ // usd chosen
useCurrency = rangeUSD;
} else if (curr.value == "eur"){ // eur chosen
useCurrency = rangeEUR;
} else {
alert('Something went wrong');
return false;
}

// how many options exists for our chosen currency (may vary)
var numberOfItems = useCurrency['txt'].length;

// lets create an object reference to the select element
// which we have named pricerange (see the html part)

var selObj = form.pricerange;

// deletes existing options which may show in the select element
for (var i=0;i< selObj.options.length; i++){
selObj.options[i].text = "";
selObj.options[i].value = "";
}

// we loop through each number of options to be added to the select
// element and populate it with the corresponding data in our chosen
// array

for (var i=0;i< numberOfItems ;i++){
// if option does not exist alredy we create one
selObj.options[i] = new Option();
selObj.options[i].text = useCurrency['txt'][i];
selObj.options[i].value = useCurrency['val'][i];
}

// we set the cheapest model as our pre-selected option
selObj.options[0].selected = true;

}

// this function simply navigates to another page when
// user choose a specific price range. You can do anything
// you want instead (this is just an example)

function navigate(selElm){

// get value of the selected option
var sel = selElm.options[selElm.selectedIndex].value;

//do not proceed if value is still '#" (our saftey valve)
if (sel == "#") {
return false;
} else {
window.location.href = sel+".html";
}

}

//-->
</script>

<!---Body--->


 <form name="money">
Select Currency:

<!-- if the user selects 'usd' then we call set with a reference to 'this' element -->
USD <input type="radio" name="currency" value="usd" onclick="set(this, this.form)">

<!-- if the user selects 'eur' then we call set with a reference to 'this' element -->
EUR <input type="radio" name="currency" value="eur" onclick="set(this, this.form)">



<!-- here our select element start. we have given it a name 'pricerange' -->
Select Price Range:

<!-- the onselect eventhandler will call the navigate function when the user selects an option -->
<select name="pricerange" onchange="navigate(this)">
<option value="#">Please select currency first</option>
</select>


</form>



No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!