Hi,
I want to validate the drop down box selection. The value for each item is either 1 char(title), 7char(name), or equal to "none". The selection is good only when user select on the name (which value contain 7 characters). So I try to trim it then find the length. If the length is not 7 then pop up the alert box.
I tried the code below but it's not working. When I click submit, I got error message "object doesn't support this property or method". When I click 'ok' to let it debug, then it highlight at this statement.
str.charAt(i)==" ";
Thanks in advance
Here is the drop down box.
Here is my validation
I want to validate the drop down box selection. The value for each item is either 1 char(title), 7char(name), or equal to "none". The selection is good only when user select on the name (which value contain 7 characters). So I try to trim it then find the length. If the length is not 7 then pop up the alert box.
I tried the code below but it's not working. When I click submit, I got error message "object doesn't support this property or method". When I click 'ok' to let it debug, then it highlight at this statement.
str.charAt(i)==" ";
Thanks in advance
Here is the drop down box.
Code:
<select name="vendor" class="ver11pxblk">
<option value="none" selected>Select One </option>
<option value="F"> --------- FREIGHT -------------</option>
<option value="FF01010"> ABC Co.</option>
<option value="FF01020"> APL Co. </option>
<option value="S"> --------- SERVICE -------------</option>
<option value="SS01010"> UPS </option>
<option value="SS01020"> DHL </option>
</select>
Code:
function rTrim(str)
{
if (str==null)
{return null;}
for(var i=str.length-1;str.charAt(i)==" ";i--);
return str.substring(0,i+1);
}
function check_input()
{
// some other input validation
if (rTrim(document.f1.vendor).length != 7)
{
alert ("Please select Issuer");
return false;
}
// some other input validation
}