As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.
Join the TIBCO Community TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.
From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
Request access to the private WebFOCUS User Group (login required) to network with fellow members.
Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.
I have 2 input fields on a form where I would want to stop user if they choose to input anything, it needs to be 9 digits. However if they choose to leave it blank, they can exit without entering. Currently, even though I leave both fields blank, the javacript pop up still shows up. I am on webfocus 7.6.4. Please let me know what is incorrect about my javascript code:
function OnButton2_Click ( ) { if (((document.adds_sav_fo.Supp_num_sav_Edit.value.length < 9) && [document.adds_sav_fo.Supp_num_sav_Edit.value.length != 0))) { alert("Duns # should be 9 digits only1"); document.adds_sav_fo.Supp_num_sav_Edit.focus();
}
else
(((document.adds_sav_fo.Supp_num1_sav_Edit.value.length < 9) && [document.adds_sav_fo.Supp_num1_sav_Edit.value.length != 0))) { alert("Duns # should be 9 digits only2"); document.adds_sav_fo.Supp_num1_sav_Edit.focus(); return(false); }
IWCTrigger("run_temp"); }This message has been edited. Last edited by: Kerry,
Webfocus Focus Unix Windows
Posts: 13 | Location: NJ, PA, DE | Registered: March 05, 2009
thansk dave and francis. Actually Francis seems to be fairly close to what I need but there are 2 issues. First, I need the user to enter only a 9 digits number but my field is A10 so user can still enter 10 digits. How do I prevent this in my javascript code? Second, with my current code below, even though user will get a pop up with 9 digits or less, it will still run my function run_submit.
I want to run function run_submit only when there are no more javascript warning.
Please let me know what I would need to accomplish the 2 above steps. This is the code I have so far:
function OnButton9_Click ( ) { if (document.adds_fo.Supp_num_Edit.value.length > 0 && document.adds_fo.Supp_num_Edit.value.length < 9) { alert("Duns # should be 9 digits only1"); } if (document.adds_fo.Supp_num1_Edit.value.length > 0 && document.adds_fo.Supp_num1_Edit.value.length < 9) { alert("Duns # should be 9 digits only2"); } IWCTrigger("run_calc"); }
Webfocus Focus Unix Windows
Posts: 13 | Location: NJ, PA, DE | Registered: March 05, 2009
Format - (like what you are doing) Required fields - Business Rules -
Format validation is best done Inline. That is the validation is triggered by the 'onblur' event, which then can use common JS functions to validate non-blank input against various data types, like Date, Numeric, or whatever.
The Required Field validation would be done in another function called by whatever button or control submits the form for Maintain processing, and would check each required input control for a non-blank value.
Business rules may call for checking a date range, or field values that depend on other field values. Sometimes it is easier to run these checks in Maintain, where JavaScript may not have access to comparison data, but this is very dependent on what input business rules must be enforced.
You should also set the focus to the control that failed validation, so the user can find and correct it quickly.
Give your input control the attribute of maxlength="9" to restrict how many characters can be input into the control, and then use JavaScript to ensure that a minimum of 9 chars have been input (using code similar to that suggested above).
if (document.adds_sav_fo.Supp_num_sav_Edit.value.length > 0 &&
document.adds_sav_fo.Supp_num_sav_Edit.value.length < 9)
{
alert("Duns # should be 9 digits only "+document.adds_sav_fo.Supp_num_sav_Edit.value.length);
}
T
In FOCUS since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2
WebFOCUS App Studio 8.2.06 standalone on Windows 10
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004
thanks all for your input. The javascript works great on blur. My question is that there is a way through click button and javascript or other means to check all conditions from the javascript before executing iwctrigger run_calc (which saves the record). This is my current script that still saves even though Duns # is less than 9 digits :
function OnButton9_Click ( ) { if ((document.adds_fo.Supp_num_Edit.value.length > 0 && document.adds_fo.Supp_num_Edit.value.length < 9) || [document.adds_fo.Supp_num_Edit.value.length == 10))
{ alert("Duns # should be 9 digits only, You have entered "+document.adds_fo.Supp_num_Edit.value.length); } if ((document.adds_fo.Supp_num1_Edit.value.length > 0 && document.adds_fo.Supp_num1_Edit.value.length < 9) || [document.adds_fo.Supp_num1_Edit.value.length == 10))
{ alert("Duns # should be 9 digits only, You have entered "+document.adds_fo.Supp_num1_Edit.value.length); }
IWCTrigger("run_calc"); }
Webfocus Focus Unix Windows
Posts: 13 | Location: NJ, PA, DE | Registered: March 05, 2009
Javascript Primers are good, but more can be achieved for validation by including regular expressions.
function OnsaveButton_Click ( ) {
str = document.getElementById("NumberEntry");
if ((str.value.match(/^[0-9]{9}$/) == null) && (str.value.length != 0)) {
alert("wrong value entered");
str.focus();
str.select();
return false
}
IWCTrigger("saveData");
}
or
function OnNumberEntry_Blur ( ) {
str = document.getElementById("NumberEntry");
if ((str.value.match(/^[0-9]{9}$/) == null) && (str.value.length != 0)) {
alert("wrong value entered");
str.focus();
str.select();
return false
}
}
This will check for 0-9 for 9 characters, or empty. You can use a blur on the data entry or a click on a button. Being pedantic it uses a better way to work with the DOM (document.getElementById("elementId")), returns false to stop any further actions and highlights the error plus an alert.
Reg Exp can be used for many complex validations within JS, including date validation, well worth examining.
Alan. WF 7.705/8.007
Posts: 1451 | Location: Portugal | Registered: February 07, 2007