cancel
Showing results for 
Search instead for 
Did you mean: 

Client side validation using javascript

Former Member
0 Kudos

Hi,

I'm very new to this. I am following the guidelines in SAP network and trying out some code.

can anyone tell me why the following<b> javascript</b> is not working??

I'm using <b>Dynpage</b>.This is one input field in my form.

 InputField first = new InputField("first");
  first.setType(DataType.STRING);
  first.setMaxlength(400);
  first.setClientEvent(EventTrigger.ON_CHANGE, "validateName()");

and the javascript code is,

Document doc = getDocument();
			doc.addRawText("<script>" +
"function validateName() " +
" { " +
" var funcName = htmlb_formid+ '_getHtmlbElementId'; " +
"func = window[funcName];" +
" var val = eval(func('first'));" +
"alert(val);" +
"var val1=val.getValue();" +
"if (val1 != 'anand') " +
"alert('Enter correct name'); "+
"if((val1.charAt(0)=='0')||"+
"(val1.charAt(0)=='1')||(val1.charAt(0)=='2')||"+
"(val1.charAt(0)=='3')||(val1.charAt(0)=='4')||"+
"(val1.charAt(0)=='5')||(val1.charAt(0)=='6')||"+
"(val1.charAt(0)=='7')||(val1.charAt(0)=='8')||"+
"(val1.charAt(0)=='9')) "+
"alert('Name should not start with a number'); }</script>");

But this is not working.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

yes.I got it now. I made a mistake.

didnt give

first.setJSObjectNeeded(true);