cancel
Showing results for 
Search instead for 
Did you mean: 

How to display the eror message in the iView

Former Member
0 Kudos

Hi

I want to check the user input in the client side and display an error message in the iView instead of displaying the error message as an alert

it is ok when I tried to do it as an alert

alert('ERROR MESSAGE');

but the problem is how to display the error message as a text in the iView ...

I wrote the below code..

any one can see it and has any sugestion?

Thanks

=============

<%@ taglib uri="tagLib" prefix="hbj" %>

<%

String compid = "";

String message = "";

%>

<hbj:content id="MyContent">

<hbj:page title = "Selection Screen">

<hbj:form id = "myForm">

<br>

<br>

<br>

<center>

<H3>Benefits Statement </H3>

<H4>Selection Screen</H4>

<hbj:gridLayout

id="FSSLayout"

debugMode="False"

width="40%"

cellSpacing="5"

>

<hbj:gridLayoutCell

rowIndex="1"

columnIndex="1"

width="10%"

horizontalAlignment="LEFT"

style="WildStyle"

>

<hbj:label

id="label_inputPernr"

required="TRUE"

text="Personal Number:"

design="LABEL"

labelFor="inputPernr"

/>

</hbj:gridLayoutCell>

<hbj:gridLayoutCell

rowIndex="1"

columnIndex="2"

width="40%"

horizontalAlignment="LEFT"

>

<hbj:inputField id = "inputPernr"

>

<%

compid=MyContent.getParamIdForComponent(inputPernr);

%>

</hbj:inputField>

</hbj:gridLayoutCell>

<hbj:gridLayoutCell

rowIndex="10"

columnIndex="1"

width="40%"

horizontalAlignment="CENTER"

colSpan="2"

>

<hbj:button id = "myButton" text="Submit.." design="EMPHASIZED"

tooltip="Click me to submit this form" onClick="ClickEvent" onClientClick="validRequired()">

</hbj:button>

</hbj:gridLayoutCell>

</hbj:gridLayout>

</center>

<p font="Arial" size=20><%= message%></p>

</hbj:form>

<SCRIPT LANGUAGE="Javascript">

function validRequired()

{

var myvar = document.getElementById('<%=compid%>').value;

var ivID='<%=componentRequest.getComponentContext().getContextName()%>';

if (myvar = " ")

{

message = "Enter Employee Number";

ivuRefresh(ivID);

htmlbevent.cancelSubmit=true;

}

}

</SCRIPT>

</hbj:page>

</hbj:content>

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Darrell Merryweather

Thank you for your cooperation

Actually, I do not understand the first way you mentioned.

could you explain it by sample example

assume I want to check 3 fields

NAME

ID

AGE

and I want to display different message for each, how can I do that?

Thank you

darrell_merryweather
Active Contributor
0 Kudos

No problem, here is an example of some html code and javascript that you can adapt to your needs. You can display this standalone to see how it works.

I hope this helps

<html>

<head>

<script language="JavaScript">

function validateForm(){

if(document.getElementById("nameField").value == "")

document.getElementById("errormessage").innerHTML = "Please enter the Name";

else if(document.getElementById("ageField").value == "")

document.getElementById("errormessage").innerHTML = "Please enter the Age";

else if(document.getElementById("idField").value == "")

document.getElementById("errormessage").innerHTML = "Please enter the id";

else

document.getElementById("errormessage").innerHTML = "";

}

</script>

</head>

<body>

<table border="0" cellpadding="0" cellspacing="0">

<tr>

<td>Name</td>

<td><input type="input" id="nameField" name="nameField"></td>

</tr>

<tr>

<td>Age</td>

<td><input type="input" id="ageField" name="ageField"></td>

</tr>

<tr>

<td>Id</td>

<td><input type="input" id="idField" name="idField"></td>

</tr>

<tr><td><font color="red"><span id="errormessage"></span></font></td></tr>

<tr><td><input type="button" name="validate" onClick="validateForm()" value="Click to validate"/></td></tr>

</table>

</body>

</html>

Former Member
0 Kudos

Thank you very much Darrell Merryweather

It is exactly what I need

but I have one more question...

I have more than one <div>

in every one I want to display a different error message...

but I want only one error message to be displayed at one time

example

when the user enters wrong entry, he will get ERROR-1

Then he corrected that error but he has another wrong entry and he should get ERROR-2

Ii do not want ERROR-1 and ERROR-2 to be displayed both in the selection screen at the same time

How can I remove the first one and display the second?

Do I need to refresh the I view?

if yes, How?

Thank you

darrell_merryweather
Active Contributor
0 Kudos

Hi

Firstly, if you only need on error message to be displayed at any one time, then perhaps simply just have the one div, but write the different error messages to it using

if(error1 != "")

innerHtml = error1;

else if(error2 != "")

innerHtml = error2;

else if(error3 != "")

innerHtml = error3;

If this doesn't suit your needs then you should be able to something like this

document.getElementById('error1').style.display = 'none';

which will hide the div completely

I hope this helps

D

darrell_merryweather
Active Contributor
0 Kudos

Hi

A good way would be to use javascript completely and create some Dynamic HTML. This is all redered and processed on the client side

Something like this should help

<html>

<head>

<script language="JavaScript">

function validate(){

document.getElementById("mydiv").innerText = "Validated";

}

</script>

</head>

<body>

<table border="0" cellpadding="0" cellspacing="0">

<tr><td>Hello</td></tr>

<tr><td><div id="mydiv"></div></td><tr>

<tr><td>Goodbye</td></tr>

<tr><td><input type="button" name="valdate" value="Validate" onClick="validate();"/></td></tr>

</table>

</body>

</html>

This simply gives you an example of how to use the Java script to dynamically display error messages on the screen instead of through an alert

I hope this helps

D