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 (apologies if it is not!):

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"-->

</div><img src="../images/spacer.gif" width="100" height="1"><a href="javascript:showHide('comp4')">CRS - VEER TOWERS</a><br><div id="comp4"><img src="../images/spacer.gif" width="150" height="1"><a href="javascript:showHide('ele4')">RESIDENTIAL</a><br><div id="ele4"><img src="../images/spacer.gif" width="200" height="1"><a href="javascript:showHide('func6')">STORAGE</a><br><div id="func6"><div><img src="../images/spacer.gif" width="250" height="1">SE<br><div id="dupmerows_19_7"><img src="../images/spacer.gif" width="300" height="1"><select size="1" name="countType_19_7"><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_19_7" value=0 onchange="return numCheck(this)"><input type="button" value="Add" onClick="dupIt('dupmerows_19_7')"> <input type="checkbox" name="countNone_19_7">Stop Tracking</div></div></div></div></div></div><p><input type="submit" value="Save Counts"></input></p>
</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... The page is already checking for a number in one field (calling onchange="return numCheck(this)")

Thanks in advance for your time and help! It is very much appreciated!
-jiggyg
 
Code:
<script type="text/javascript">
[!]
function validate(frm) {
   if (frm.elements["countType_11_0"].value == 0) {
      alert("this dropdown can\'t be 0");
      return false;
   }
   //continue for each dropdown in the form that can't be 0
   return false;
}[/!]

</script>
<form name="form1" method="post" action="AssignCountTypes_action.asp" [!]onsubmit="return validate(this)"[/!]>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
Hey jiggy, did you forget about this thread? Did this answer your question?

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top