• 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

javascript not working

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,


I have IE7.
I have code in javascript in my jsp as


function check()

{

var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

for (var i = 0; i < document.frm.name.value.length; i++) {
if (iChars.indexOf(document.frm.fieldname.value.charAt(i)) != -1) {
alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
return false;
}
}


return true;
}


and my jsp code

<s:form name="frm" action="customer.action" method="post" validate="true" onsubmit="javascript:return check();">
<s:textfield name="name" key="name" size="20" maxlength="20"/>


I want user not enter any special charactes in the name field.


so its giving me in javascript function as charAt(number) is undefined.

simliarly frm is undefined whicj is the form name I have given,

Please help.
 
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
UseCodeTags
ItDoesntWorkIsUseless
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very similar thread: https://coderanch.com/t/488100/HTML-JavaScript/Javascript-document-forms

Eric
 
ujwwala tem
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Thanks for the reply but still I am having trouble

I have IE7

My javascript code :
function check(){
alert("hi");
var myRegxp = /^([a-zA-Z0-9_-]+)$/;
var nameele=document.getElementById("custName");

alert(nameele.valueOf());


if(myRegxp.test(nameele)==false) {
alert("Special characters are not allowed. Please use only characters on your keyboard.");

}
}


and my jsp code


<s:form name="frm" action="customer.action" method="post" validate="true" onsubmit="check();">

<s:textfield name="custName" key="name" size="20" id="custName" maxlength="20"/>


I want to access the custname i javscript but I am not getting any value kind of,

Please reply for how should I access custname in javascript

Regards,
Ujwwala
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am guessing you did not read Bear's post.

Eric
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


nameele is an object, not a string.

Eric
 
ujwwala tem
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

Thanks for the reply but still I am facing problem here,

I have read the codetags usage and will write from next time.

I am not understanding why there is no value as such, althogh namele is an object but I want to get the custname so how should I access that in my javascript,Please help,

Thanks and Regards,
Ujwwala
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to reference the value of the object

Hint:


This is JavaScript Forms 101

Eric
 
Always! Wait. Never. Shut up. Look at this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic