0

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

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Taywin
0

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?

0

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; 
}
0

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; 
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.