Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onclick of a multiselect

Status
Not open for further replies.

jt8941

Programmer
Dec 9, 2003
15
0
0
US
I am trying to invoke an edit on a multiselect list, however, I would like to do it when they click on each item. I have two questions
1. So far I haven't been able to get the onClick event to work in each <option> tag. Is this possible?
2. I can get this done with the onClick in the <select> tag, but I need to know what option the user just clicked on to invoke that onClick event. How would this be done.
 
onChange not onClick. Then just call a function that does what ever you want to happen.

Cheech

[Peace][Pipe]
 
However, I need to keep track of which value they changed to validate that it was an correct selection. Is there anyway to pass in that value they selected to my function?
 
I posted some code for a page that adds up fields in a form, but the basic premise is there. Have a look at this code and tweek it for you purposes.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function sumup(){
if (document.forms.form1.painting.value == "0"){
paintval=0;
}
if (document.forms.form1.painting.value == "painting1"){
paintval=1;
}
if (document.forms.form1.painting.value == "painting2"){
paintval=2;
}
if (document.forms.form1.painting.value == "painting3"){
paintval=3;
}
quantval = document.forms.form1.quantity.value;
mountval = document.forms.form1.mounting.value;
totalval = (paintval*quantval) + (mountval*quantval);
document.forms.form1.total.value = totalval;
}
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <p>
    <select name="painting" id="painting" onChange="return sumup();">
      <option value="0" selected>** Please select **</option>
      <option value="painting1">Painting 1 - &pound;1</option>
      <option value="painting2">Painting 2 - &pound;2</option>
      <option value="painting3">Painting 3 - &pound;3</option>
    </select> 
  Which Painting<br>
  <input name="quantity" type="text" id="quantity" value="0" size="5" onChange="return sumup()">
How many?<br>
<select name="mounting" id="mounting" onChange="return sumup()">
  <option value="0">** Pease Select **</option>
  <option value="2.50">Canvas - £2.50</option>
  <option value="3.99">Stretched - £3.99</option>
  <option value="4.99">Framed &amp; Stretched - £4.99</option>
</select> 
Mounting Options?
</p>
  <p>
    <input name="total" type="text" id="total" value="0" size="8" readonly>
Total Cost (Quantity * (Painting choice + Mounting cost)) </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

Cheech

[Peace][Pipe]
 
I get it but I need to know which value they just selected to validate it, and remember this is a multi-select list.

For example lets say the user selects Painting 1 first. After selecting painting 1 the user can not select painting 3. Now if they select painting three, I need to return a message saying that is an invalid choice and deselect painting 3. Therefore I need the last selection made in order to validate my list.

Hopefully that made my problem more clear.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top