aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes javascript not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript not working" Watch "javascript not working" New topic
Author

javascript not working

ujwwala tem
Ranch Hand

Joined: Feb 10, 2010
Posts: 83
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

UseCodeTags
ItDoesntWorkIsUseless


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Very similar thread: http://www.coderanch.com/t/488100/HTML-JavaScript/Javascript-document-forms

Eric
ujwwala tem
Ranch Hand

Joined: Feb 10, 2010
Posts: 83
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
I am guessing you did not read Bear's post.

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6


nameele is an object, not a string.

Eric
ujwwala tem
Ranch Hand

Joined: Feb 10, 2010
Posts: 83
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to reference the value of the object

Hint:


This is JavaScript Forms 101

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript not working