Dropdown events...

1

116

I am attempting to use the below script, but I notice that the 'onclick'
requires 2 clicks. Why 2 clicks? I'm guessing select is a seperate click?
<script type="text/javascript">
function doctypeno()
{
with (document.forms[0])
{
var typeno; //case variable
var hdnt;
hdnt = "";
typeno = dcl_TYPE.value;
hdnt = hdnTYPE.value;
T2.value = hdnt;

switch (typeno)
{
case '':
hdnTYPE.value = "";
break;
case '00':
hdnTYPE.value = "";
break;
case '01':
hdnTYPE.value = "P ";
break;
case '02':
hdnTYPE.value = "F ";
break;
case '03':
hdnTYPE.value = "WI";
break;
}
}
}
</script>

David
 
T

Trevor Lawrence

David,

I am not sure about the two clicks because I can't see your HTML, but I
tried the code below and it needs a onSubmit= to do anything with the
dropdown list.

I think your assumption is correct -
Click 1: Select an item
Click 2: Do something with it

<html>
<head>
<script type="text/javascript">
function loadDates() {
var yr = new Date().getFullYear();
var x = document.getElementById('mySelect');
for (var i = 1; i < x.options.length; i++) {
x.options.text = yr + (i-1);
}
}
function alt() {
var x = document.getElementById('mySelect');
alert (x.options[x.selectedIndex].text);
}
</script>
</head>
<body onload="loadDates()">
<form action="" onSubmit="alt()">
<select id="mySelect">
<option>Select one...</option>
<option></option>
<option></option>
<option></option>
<option></option>
</select> <br>
<input type="submit" value="Submit">
</form>

</body>
</html>
 
1

116

Thanks. Thats what I ended up doing. Having no 'onselect' was the issue.
Working fine thru the onSubmit.

David

Trevor Lawrence said:
David,

I am not sure about the two clicks because I can't see your HTML, but I
tried the code below and it needs a onSubmit= to do anything with the
dropdown list.

I think your assumption is correct -
Click 1: Select an item
Click 2: Do something with it

<html>
<head>
<script type="text/javascript">
function loadDates() {
var yr = new Date().getFullYear();
var x = document.getElementById('mySelect');
for (var i = 1; i < x.options.length; i++) {
x.options.text = yr + (i-1);
}
}
function alt() {
var x = document.getElementById('mySelect');
alert (x.options[x.selectedIndex].text);
}
</script>
</head>
<body onload="loadDates()">
<form action="" onSubmit="alt()">
<select id="mySelect">
<option>Select one...</option>
<option></option>
<option></option>
<option></option>
<option></option>
</select> <br>
<input type="submit" value="Submit">
</form>

</body>
</html>

--
Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org
116 said:
I am attempting to use the below script, but I notice that the 'onclick'
requires 2 clicks. Why 2 clicks? I'm guessing select is a seperate
click?
<script type="text/javascript">
function doctypeno()
{
with (document.forms[0])
{
var typeno; //case variable
var hdnt;
hdnt = "";
typeno = dcl_TYPE.value;
hdnt = hdnTYPE.value;
T2.value = hdnt;

switch (typeno)
{
case '':
hdnTYPE.value = "";
break;
case '00':
hdnTYPE.value = "";
break;
case '01':
hdnTYPE.value = "P ";
break;
case '02':
hdnTYPE.value = "F ";
break;
case '03':
hdnTYPE.value = "WI";
break;
}
}
}
</script>

David


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top