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!

Newbie?: Check Value In Dropdown/Select

Status
Not open for further replies.

jiggyg

Programmer
Oct 1, 2007
61
0
0
US
hello!

I have a question on how to verify the value in select box; if a value isn't selected, I want to do an alert box "Please select count type."

I've been told before to post the source, so I hope this is right:
Code:
<html>
<head>
<link href='include.css' type='text/css' rel='stylesheet'/>
<script language="JavaScript">
function dupIt(itm){
	var dup = document.getElementById(itm);
	var clone = dup.cloneNode(true);
	var cloned = dup.parentNode.appendChild(clone);
	cnt = cnt + 1;
	
	cloned.childNodes[2].value = 0;
	
	itm = cloned.childNodes[1].name;
	var itmID = itm.substring(itm.indexOf("_") + 1, itm.lastIndexOf("_"));
	
	//rename objects to make unique
	cloned.id = "dupmerows_" + itmID.toString() + "_" + cnt.toString()
	cloned.childNodes[1].name = "countType_" + itmID.toString() + "_" + cnt.toString()
	cloned.childNodes[2].name = "countName_" + itmID.toString() + "_" + cnt.toString()
	cloned.childNodes[3].name = "countNone_" + itmID.toString() + "_" + cnt.toString()
}
function showHide(itm){
	itm = document.getElementById(itm);
	if(itm.style.display=="none"){itm.style.display="block"}
	else{itm.style.display="none"}
}
function filterPage(itm){
	document.forms[0].action="assignCountTypes.asp";
	document.forms[0].submit();
}
function numCheck(thisVar){
	ln1 = thisVar.value.length;
	for(i=0;i<ln1;i++){
	str = thisVar.value.charAt(i);
	if(str<'0'||str>'9'){
		alert("Please enter only whole numbers.");
		thisVar.value = "";
		thisVar.focus();
		return false
		}
	}
}
</script>
</head>

<body>
<form name="form1" method="post" action="AssignCountTypes_action.asp">
<select size="1" name="filterVal" onChange="filterPage(this)"><option value=0>Show All Count Types</option><option value=-1 >Show All Unassigned</option><option value =1>PARKING</option><option value =2>PARKING-2</option><option value =3>SEATING</option></select><br><p><input type="submit" value="Save Counts"></input></p><img src="../images/spacer.gif" width="50" height="1"><a href="javascript:showHide('blk1')">BLOCK A</a><br><div id="blk1"><img src="../images/spacer.gif" width="100" height="1"><a href="javascript:showHide('comp1')">ACC - CONVENTION CENTER</a><br><div id="comp1"><img src="../images/spacer.gif" width="150" height="1"><a href="javascript:showHide('ele1')">RETAIL</a><br><div id="ele1"><img src="../images/spacer.gif" width="200" height="1"><a href="javascript:showHide('func1')">AIS</a><br><div id="func1"><div><img src="../images/spacer.gif" width="250" height="1">S<br><div id="dupmerows_11_0"><img src="../images/spacer.gif" width="300" height="1"><select size="1" name="countType_11_0"><option value=0>Please Select...</option><option value =1 selected>PARKING</option><option value =2>PARKING-2</option><option value =3>SEATING</option></select><input size="10" type="text" name="countName_11_0" value=20 onchange="return numCheck(this)"><input type="button" value="Add" onClick="dupIt('dupmerows_11_0')"> <input type="checkbox" name="countNone_11_0">Stop Tracking</div></div></div><img src="../images/spacer.gif" width="200" height="1"><a href="javascript:showHide('func2')">AV</a><br><div id="func2"><div><img src="../images/spacer.gif" width="250" height="1">2<br><div id="dupmerows_9_1"><img src="../images/spacer.gif" width="300" height="1"><select size="1" name="countType_9_1"><option value=0>Please Select...</option><option value =1>PARKING</option><option value =2>PARKING-2</option><option value =3>SEATING</option></select><input size="10" type="text" name="countName_9_1" value=0 onchange="return numCheck(this)"><input type="button" value="Add" onClick="dupIt('dupmerows_9_1')"> <input type="checkbox" name="countNone_9_1">Stop Tracking</div></div></div></div><!--close ele0"-->
</div><img src="../images/spacer.gif" width="100" height="1"><a href="javascript:showHide('comp2')">AHR - FLRS 17-62 - AS REPORTED FROM 11/1/2007 PLINES</a><br><div id="comp2"><img src="../images/spacer.gif" width="150" height="1"><a href="javascript:showHide('ele2')">(blank)</a><br><div id="ele2"><img src="../images/spacer.gif" width="200" height="1"><a href="javascript:showHide('func3')">(blank)</a><br><div id="func3"><div><img src="../images/spacer.gif" width="250" height="1">(blank)<br><div id="dupmerows_18_2"><img src="../images/spacer.gif" width="300" height="1"><select size="1" name="countType_18_2"><option value=0>Please Select...</option><option value =1>PARKING</option><option value =2>PARKING-2</option><option value =3>SEATING</option></select><input size="10" type="text" name="countName_18_2" value=0 onchange="return numCheck(this)"><input type="button" value="Add" onClick="dupIt('dupmerows_18_2')"> <input type="checkbox" name="countNone_18_2">Stop Tracking</div></div></div></div><!--close ele1"-->
</form>

</body>
<script language="JavaScript">
 var cnt = 5
</script>
</html>

So, if this:
<option value=0>Please Select...</option><option value =1>PARKING</option><option value =2>PARKING-2</option><option value =3>SEATING</option></select>

is zero(0), ask them to select a value...

Here's my asp in case I posted the wrong stuff above:
Code:
Response.Write "<div id=""dupmerows_" & aInfo(7,i) & "_" & cnt & """>"

 Response.Write dtlSpacer & "<select size=""1"" name=""countType_" & aInfo(7,i) & "_" & cnt &""">"
  Response.Write"<option value=0>Please Select...</option>"
     for x = 0 to ubound(countType, 2)
	Response.Write"<option value =" & countType(0,x)
	  if countType(0,x) = aInfo(8,i) then
	    Response.Write " selected"
	  end if
	Response.Write ">" & countType(1,x) & "</option>"
     Next
 Response.Write "</select>"

 Response.Write "<input size=""10"" type=""text"" name=""countName_" & aInfo(7,i) & "_" & cnt & """ value=" & aInfo(6,i) & " onchange=""return numCheck(this)"">"

 Response.Write "<input type=""button"" value=""Add"" onClick=""dupIt('dupmerows_" & aInfo(7,i) & "_" & cnt & "')"">"
   'add way to remove from list
   response.write " <input type=""checkbox"" name=""countNone_" & aInfo(7,i) & "_" & cnt & """>Stop Tracking"

response.write "</div>"

Thanks in advance for your time and help! It is very much appreciated!
-jiggyg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top