Hi, I am using 2 list boxes with 4 values in each. I want to create an action when a button is pressed on the form which will be something like this:

If(value of list box1 is 1 and value of list box2 is 1)
{
total = total + 1;
}
elseif(value of listbox1 is 1 and value of listbox2 is 2)
{
total = total + 2;
}... and so on

anyway thats what I want to happen, but Iv tried a few things, and none have worked. All I want to do is check the value of my list boxes then increase a variable by a certain amount. I have declared my total variable but I cant get it to work, if anyone has a solution it would be great.

Cheers

Member Avatar for diafol

This sounds like a simple js solution (use javascript to get values from onclick events).

You can set the input box, "total", thus:

...(label)...
<select id="base_no" onclick="doMulti();return false;">
  <option value="1">1</option>
  ...(more)...
</select>
  ...(label)...
<select id="multiplier" onclick="doMulti();return false;">
  <option value="7">Multiply by 7</option>
  ...(more)...
</select>
  ...(label)...
<input type = "text" name="total" id="total" value="0" />

The js either goes into into the head inside a script tag or into an external js file.

function doMulti(){
  n = document.getElementById('base_no').value;
  m = document.getElementById('multiplier').value;
  t = n * m;
  document.getElementById('total').value = t;
}

The above is a trivial solution, a production solution would involve a more rigorous methodology, including server-side validation.

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.