Javascript Option/Select Box Validation?

Is it possible to check an option/select box to see if it still has data in it?

I’d like to be able to stop a user from updating a file IF the field they are copying from still has content in it.

I.e.

BOX 1 BOX 2
1 3
4
6
2
5

So the button will display an error message (e.g. you aint sent the entire lot over)

I’ve tried to attempt it but my mind cannot really handle anything more than (Check kettle for water, IF water equal or less than 1 cup full, then fill kettle with water, If kettle equal to or greater than 3 then STOP)

Cheers Dom

Yeah, it’s pretty easy to do. I can’t get any code to you yet, since I just got swamped at work, but on my lunch break I’ll come back hopefully, with some code that’ll do the trick. If this is urgent, then I would post in the DHTML/Javascript forum and they can get you an answer before my lunch break :slight_smile:

Drew

I’ll look forward to it…

Hopefully i’ll be able to understand it :o

thanks for the reply :slight_smile:

Im sorry about the wait. Here is the code I came up with. I hope it does what you want. Let me know if I didn’t interpret you correctly.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>

<script language= "Javascript">
function checkSelect () {
  if (document.form1.submitOK.value == "false") {
  	 alert ("You still have a value selected")
	 return false;
	 document.form1.select.focus()
  }
}
function selected(x) {
  document.form1.select.options[x].selected = true;
  if (x != 0) {
  	 document.form1.submitOK.value = false;
  }
  else {
  	 document.form1.submitOK.value = true;
  }
}
</script>
</head>

<body>
<form name="form1" method="post" onSubmit="checkSelect();">
<select name="select" onChange="selected(this.options[this.selectedIndex].value);">
	<option value="0">None</option>
	<option value="1">Red</option>
	<option value="2">Blue</option>
	<option value="3">Yellow</option>
</select>
<input type="hidden" name="submitOK">
<input type="submit" value="submit">
</form>

</body>
</html>


Drew