View Full Version : Detecting Left Numerical Value in form
bspahr
01-26-2004, 07:00 PM
I have this form:
http://www.areafifty1.com/dev/form.htm
If a user selects time slot 2 and a Saturday date, I want to bring up an alert informing the user that they must select the AM time slot for Saturday deliveries only.
I think I am close with this code, but can't figure out how to retrieve only the single left # to see if it is a 9 or not.
if (thisform.frmPickup.rdoTimeSlot.value == "2" || thisform.frmPickup.rdoLocation.value == "9")
{
alert("You must select the AM time slot for Saturday deliveries only")
return false
}
Garadon
01-26-2004, 07:52 PM
function valbutton(thisform)
{
// validate time slot
myOption = -1;
for (i=0; i<thisform.rdoTimeSlot.length; i++)
{
if (thisform.rdoTimeSlot[i].checked)
{
myOption = i;
}
}
if (myOption == -1)
{
alert("You must select a time slot");
return false;
}
// validate location
myOption1 = -2;
for (i=0; i<thisform.rdoLocation.length; i++)
{
if (thisform.rdoLocation[i].checked)
{
myOption1 = i;
}
}
if (myOption1 == -2)
{
alert("You must select a location");
return false;
}
//check Sat. deliveries
if (thisform.rdoTimeSlot[myOption].value == "2" && Math.floor(thisform.rdoLocation[myOption1].value/10) == "9")
{
alert("You must select the AM time slot for Saturday deliveries only")
return false
}
thisform.submit(); // this line submits the form after validation
}
Shucks got beat, Oh well, might as well post my humble attempt as well.
//check Sat. deliveries
if (thisform.rdoTimeSlot[1].checked){
for (i=0; i<thisform.rdoLocation.length; i++) {
if(thisform.rdoLocation[i].checked&&thisform.rdoLocation[i].value == "91"||thisform.rdoLocation[i].checked&&thisform.rdoLocation[i].value == "92"){
alert("You must select the AM time slot for Saturday deliveries only")
return false
}
}
}
bspahr
01-26-2004, 08:16 PM
Garadon
This didn't work when I cut and pasted it into my file.
bspahr
01-26-2004, 08:39 PM
I forgot to rename myOption to myOption1.
One question: How does this part work?
(thisform.rdoLocation[myOption1].value/10) == "9")
Here is the working code:
<script language="javascript">
function valbutton(thisform) {
// validate time slot
myOption = -1;
for (i=0; i<thisform.rdoTimeSlot.length; i++) {
if (thisform.rdoTimeSlot[i].checked) {
myOption = i;
}
}
if (myOption == -1) {
alert("You must select a time slot");
return false;
}
// validate location
myOption1 = -1;
for (i=0; i<thisform.rdoLocation.length; i++) {
if (thisform.rdoLocation[i].checked) {
myOption1 = i;
}
}
if (myOption1 == -1) {
alert("You must select a location");
return false;
}
//check Sat. deliveries
if (thisform.rdoTimeSlot[myOption].value == "2" && Math.floor(thisform.rdoLocation[myOption1].value/10) == "9")
{
alert("You must select the AM time slot for Saturday deliveries only")
return false
}
thisform.submit(); // this line submits the form after validation
}
</script>
Garadon
01-26-2004, 08:50 PM
by dividing any number by ten u move the decimals on space left.
eksamepls
91/10=9,1
by flooring any number u cut of the decimals
Math.floor(9,1)=9
so by doing
Math.floor(A/10);
A being a 2 digit number u will always get the left most digit.
bspahr
01-26-2004, 08:56 PM
Thanks for info.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.