Hello
Can you please help me with this easy cake,

On a form I have 4 listboxes
listbox1 listbox2 listbox3 listbox4

What I need is to count the listboxes which values selected are = 1. and display the result in a textbox1

For example : if listbox1 and listbox3 are selected with value = 1 then the result in the textbox1 is 2, obviously because are 2 listboxes with value 1

So what the relationship among all listbox here? Do you have any certain rules, such as listbox1 + listbox2 + listbox3 - listbox4? Do you have a separate output display element after you done with it?

Thank you Taywin
I'm using this code on onchange envent of each listbox
, I don't know where the problem is, but it's returning

function doSomething() { 
    var sel1 = document.getElementById("ListBox1"); 
    var sel2 = document.getElementById("ListBox2"); 
    var count = 0; 
 
    if (sel1.value == 1) 
        count++; 
    if (sel2.value == 1) 
        count++; 
 
    document.getElementById("Textbox1").value= count; 
}

What your code does is to check if a user selects the choice with value 1 in ListBox1 and/or ListBox2. Then it increments the count and place the value inside your Textbox1 element. If you want a very simple add, you could copy and paste up to 4 boxes. However, I am not really sure that it is the true exercise you are doing???

function doSomething() { 
    var sel1 = document.getElementById("ListBox1"); 
    var sel2 = document.getElementById("ListBox2"); 
    var sel3 = document.getElementById("ListBox3"); 
    var sel4 = document.getElementById("ListBox4"); 
    var count = 0; 
 
    if (sel1.value == 1) 
        count++; 
    if (sel2.value == 1) 
        count++; 
    if (sel3.value == 1) 
        count++; 
    if (sel4.value == 1) 
        count++; 
 
    document.getElementById("Textbox1").value= count; 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.