Here are some functions I wrote for dealing with select boxes...

function setSelectByValue(id, v){
        var o = $(id).options;
        for (var index = 0; index < o.length; ++index) {
                 var item = o[index];
                 if(v == item.value){
                        s.options.selectedIndex = index;
                        return true
                 }
        }
        return false
}

function setSelectByText(id, t){
        var o = $(id).options;
        for (var index = 0; index < o.length; ++index) {
                 var item = o[index];
                 if(t == item.text){
                        s.options.selectedIndex = index;
                        return true
                 }
        }
        return false
}

function removeOption(id, v){
        if(v == "all"){ // Remove all options
                $(id).options.length = 0;
                return true;
        }
        // remove options with matching value.
        var o = $(id).options;
        for (var index = 0; index < o.length; ++index) {
                 var item = o[index];
                 if(v == item.value){
                        o[index] = null;
                        return true
                 }
        }
        return false
}


function addSelectOption(id,t,v ){
        var optn = document.createElement("OPTION");
        optn.text = t;
        optn.value = v;
        $(id).options.add(optn);
}



______________________________________________________________________
Alex Duffield ❖ Principal ❖ InControl Solutions . http:// 
www.incontrolsolutions.com



On 6-Jun-07, at 8:50 AM, Programme wrote:

>
> Hi
>
> I'll get to it right away:
>
> 1. I have a simple page with a form, in this form there is a "select"
> box with a number of options. On the right i also have a "input" field
> with a submit option.
>
> 2. When the user puts something in the input field and hits submit, a
> php script is run, that puts that entry in mysql table.
>
> Question:
>
> 3. How do i with Ajax update the "select" box, so that the user can
> see the last entry there.
>
> Yes i want to use Ajax so that only the "select" box is updated, the
> rest of the page and form stays as it is. I have read on new
> ajax.updater and onComplete, onSuccess and so on using prototype, but
> have not yet figured it out, hope there is someone that can help.
>
> Programme
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to