• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

onBlur javascript validation in struts

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I was trying onBlur javascript function in struts framework n it is giving an error. my sample coding is below please advise me whatz wrong in my coding.
Thanks
Regards
Jowsaki

function validate()
{
var valid="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstvwxyz1234567890";
var ok = "yes";
var temp;
var field = window.document.contentForm.custID;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if(valid.indexOf(temp) == "-1") ok = "no";
}
if(ok == "no") {
alert("Invalid entry !!! Only characters and numbers are accepted !");
field.focus();
field.select();
}

<tr>
<td width="20%"><div align="right"><strong>Cust ID:</strong></div></td>
<td width="30%"><div align="left"><html:text property="custID" style="width=220" onBlur="validate(this)"/></div></td>
<td width="20%"><div align="right"><strong>User Keyword:</strong></div></td>
<td width="30%"><div align="left"><html:text property="userID" style="width=220" onBlur="validate(this)" /></div></td>
</tr>
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to JavaScript/HTML
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might be helpful if you told us what the error was...
bear
 
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this
function validate(custID)
{
var number_format = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopgrstuvwxyz0123456789";
for (var i = 1; i < custID.value.length; i++)
{
check_char = number_format.indexOf(custID.value.charAt(i))
if (check_char < 0)
{alert("Only letters and digits");
return false;

}
else
{
//alert("heyy");
return true;
}

}

}
 
reply
    Bookmark Topic Watch Topic
  • New Topic