Repost - javascript function calling

Hi there,

I have a web form that is built in notes and it has an embedded javascript library which handles the validation.

If a field is empty it puts focus on the first empty field in the list of ‘empty fields’ returned by the validation code.

This worked fine until i added a tab and two divs which alternate being hidden or shown on the form based on which tab you click.

Now if i am on the second tab which is where the validation button is and the field that is empty is on the first tab the code fails because it cannot find the field to focus on.

This is a problem i am familiar with in the lotus notes client so i thought i would have a crack at fixing it myself :slight_smile:

I also have a small function in the js header of the lotus notes form which swaps the two divs around. Here is the code for that

function toggleLayer(showLayer, hideLayer){

showDiv = document.getElementById(showLayer);

hideDiv = document.getElementById(hideLayer)

showDiv.style.display=“block”;

hideDiv.style.display=“none”;

}

I copied this function into the javascript library so i could call it from there. Now what i do is pass in which tab the field for validation is on and when a field fails validation i call this function to switch the required tab to visible and hide the other. then when the focus to the field is set by the validation code it should work…

The code doesn’t error but i need to somehow refresh the page so that it acts out the switch of DIV in the ui.

Putting location.reload didnt work, when i tried to switch to the second tab it was somehow running this command in my validation code and kept refreshing the page back to the first div.

I hope this makes sense. But i am trying to find the method to get this to work. This is my first web project in Lotus Notes, and out of lotus notes, so any help would be greatly appreciated.

Stephen (too scared to take R7 web developer exam)

Subject: repost - javascript function calling

Hello!

I’ve done tons of Notes web apps, and I feel your pain with this issue. =8P You don’t really need to refresh the document, and you understand the problem well. However, I’m not sure if I can solve it for you.

If there were a javascript equivalent for “@Do”, you could set the order to show the proper tab and then focus on the proper field. I don’t know of one, so perhaps, you can just switch tabs, and add a style to highlight the offending field instead of focusing on it.

Or, you could try the setTimeout method on the field.focus to give time for the code to switch tabs.

Best of luck!

Steve in NYC

“It hurts to be on the cutting edge.”

Subject: RE: repost - javascript function calling

Hi there,

I will look into highlighting the table cell in red if the field needs to be populated, then i can simply switch the tab and it will be visible which fields need populating

Thanks for your help :slight_smile:

Subject: repost - javascript function calling

Stephen,

From what you are saying you want to do, you do NOT want to reload the page in the browser. This will reload the document with the initial setting it had (and thus your tab changes will be hidden again). Can you post all of your validation code? Is the field you are setting focus to visible or hidden? It can’t be hidden if you are setting focus to it.

basically what you want to do is this in the validation

x = doValidation(param1, param2, etc);

if (x == False){

//or however your fail condition is handled

failLayer = theFailLayer //(however you get this… or could be the name of the field)

toggleLayer(showLayer, hideLayer);

Could probably tell you more if you post all of your code. You definately do not want to reload the page to do this.

One technique I have found that works well with users is to use a small graphic next to the label in order to indicate required fields, then when you validate, create an array of all of the fields that failed validation (ideally a 2D array of the field name and the error). Then display them near the button used to submit the form. The field name should be a link that is used to set the focus on the offending field. This allows your users to hop directly to the fields one at a time instead of trying multiple submits to get all of their errors. Also, more work, but very nice, is to provide a visible error graphic next to each field that caused an error (remember to only show them if validation failed for that field).