cancel
Showing results for 
Search instead for 
Did you mean: 

Error message code on BSP Page

Former Member
0 Kudos

Hi experts,

I have one code like this :

<%

IF co_model->firstname CA '+-=<>()'.

%>

<script language = "Javascript">

alert ("First name is not correct")

</script>

<%ENDIF.%>

It is showing only warning message and allowing to save the data of BSP Page when press Save Button.

In need to convert this alert (Warning) message into Error Message,

Please help, it is urgent,

Thanks in advance,

Study SAP

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This is correct as the variable <b>co_model->firstname</b> is still not changed with the value you entered on the screen. It will change after one server trip...but the code is checking this before the server trip on the client side....

To avoid this try using the indexOf function of JavaScript....which basically check the occurence of a particular string in another string.

I will try and attach a sample code....

Hope this helps.

<b><i>Do reward each useful answer..!</i></b>

Thanks,

Tatvagna.

Former Member
0 Kudos

Ok,

Try this...the following two JavaScript functions checks if the string is all numeric or not....


function checkName()
{
if( null == document.getElementByName(firstname).value || "" == document.getElementByName(firstname).value || !allDigits(document.getElementByName(firstname).value) || !isInitial(document.getElementByName(firstname).value))
           {
               alert('New Entry is not null or Zero');
               return false;
           }


}

function allDigits(str)
{
   return inValidCharSet(str," .0123456789");
}

function inValidCharSet(str,charset)
{
   var result = true;
   var count = 0;
   var str_len = str.length;
   var index = str.indexOf(".");
   for (var i=0;i<str_len;i++)
   {
      if (charset.indexOf(str.substr(i,1))<0)
      {
	  result = false;
	  break;
      }
   }
   return result;
}

Try and modify this a bit...and you will get the expected results...

Former Member
0 Kudos

Thanks Tatvagna,

This code is working same as last code, the problem remains the same.

When I am changing the value, it is not considering changed value on screen.

It is considering old value.

Thanks in advance,

Study SAP

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try using this inside a function or something.....

eg, if you want this onClick of a button,

          <htmlb:button id            = "Save"
                        text          = "Save"
                        disabled      = "FALSE"
                        design        = "EMPHASIZED"
                        onClick       = "onInputProcessing"
                        onClientClick = "if(!checkName()){htmlbevent.cancelSubmit=true;}" />



<script language = "Javascript">
function checkName(){
<%
IF co_model->firstname CA '+-=<>()'.
%>

alert ("First name is not correct")
return false;
<%ELSE.%>
return true;
<%ENDIF.%>
}
</script>

But also, for the record, it is not advisable to combine javascript and ABAP....

so you can also use the string.indexOf() function in javascript to check if the name contains special characters that you mentioned.....

Hope this helps.

<b><i>Do reward each useful answer..!</i></b>

Thanks,

Tatvagna.

Former Member
0 Kudos

Thanks Tatvagna,

This code is working fine, but there is one problem, when I am clicking on Save Button, it is considering my earlier value for checking the name.

It does not consider the current value, when i changed the previous value on this page.

Please help,

Thanks in advance,

Study SAP