
var params = document.URL.split(“?maximum”)[1];This example means that the actual location address, the URL, will be split from the questionmark onwards. This part usually contains the parameters and its values. Those we want to use and detect. After that, we want to tell where the value is. We are doing this with this part of the script.
var par1 = 0;
if (params != null ) try {par1=params.split(“=”)[1];} catch (e) {}
There we tell that the actual value is located after the equal sign (=). This value is important for continuing in the script.
switch (par1) {
case “8″:
document.write(“Micronesia is small”);
break;
case “9″:
document.write(“Micronesia is far away”);
break;
default:
document.write(“Micronesia is far away and very small”);
}
Above, we specify each value and write the content. If the value for the variable is 8 (in our example: page.html?maximum=8), then the content "Micronesia is small" (without quotationmarks) will be displayed. It works the same way with the value 9 which will post "Micronesia is far away" (without quotationmarks as well). If there is NO value specified in the URL, the defualt content will be posted, which is in the above example "Micronesia is far away and very small" (again without quotation marks).
So, now we have the full script!
<script type=”text/javascript”>
var params = document.URL.split(“?maximum”)[1];
var par1 = 0;
if (params != null ) try {par1=params.split(“=”)[1];} catch (e) {}
switch (par1) {
case “8″:
document.write(“Micronesia is small”);
break;
case “9″:
document.write(“Micronesia is far away”);
break;
default:
document.write(“Micronesia is far away and very small”);
}
</script>
I hope this helped you creating a professional looking website with parameters even with a free hosting package!
Added by vareside on October-27-2009, 6:20 am
