• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript not working

 
ujwwala tem
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
ujwwala tem
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am guessing you did not read Bear's post.

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to reference the value of the object

Hint:


This is JavaScript Forms 101

Eric
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic