Javascript Dropdowns

Associate
Joined
21 Sep 2005
Posts
180
Location
Dundee
I know next to nothing about JavaScript and am figuring out how to do something. I thought I'd run my ideas past you folks and see if maybe I'm making life hard fro myself.

I have 3 dropdowns. When any of the 3 are changed by the user, I'd like it to trigger an onchange event. This would call a function that would then check the current values of the other 2 dropdowns, do a bit of artithmetic with the 3 separate values and then update a value displayed on screen elsewhere.

As a final hope, I'd like any changes to be maintained for the user to view as they navigate from page to page until they change another value or they leave the site. I'm sure this is pretty simple to do..... if I knew anything about JS. Am happy to work it out but any pushes/advice in the right direction would be appreciated.

Cheers.
 
Think I've got it to the point where I can start doing the arithmetic bit which can't be too hard. Is there a more elegant way of doing it than the below?

It's not critical for the data to be carried page to page and I note the cookie idea but am trying to avoid cookies. Any other way of doing it without involving the database and a bit of Ajax?

Code:
$(document).ready(function(){
        
        $("#kids").change(onSelectChange);
        $("#hours").change(onSelectChange);
        $("#mins").change(onSelectChange);
        
    });
 
    function onSelectChange(){
        var selected = $("#kids option:selected");
        var kids = selected.text();
        var selected = $("#hours option:selected");
        var hours = selected.text();
        var selected = $("#mins option:selected");
        var mins = selected.text();        
        
        var output = "";
        
            output = "Kids " + kids + "<br />";
            output = output + "Hours " + hours + "<br />";
            output = output + "Mins " + mins + "<br />";
        
        $("#output").html(output);
    }

Edit; Forgot to mention, this uses jquery.
 
Back
Top Bottom