Focal Point Banner


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.

New TIBCO Community Coming Soon
In early summer, TIBCO plans to launch a new community—with a new user experience, enhanced search, and expanded capabilities for member engagement with answers and discussions! In advance of that, the current myibi community will be retired on April 30. We will continue to provide updates here on both the retirement of myibi and the new community launch.

What You Need to Know about Our New Community
We value the wealth of knowledge and engagement shared by community members and hope the new community will continue cultivating networking, knowledge sharing, and discussion.

During the transition period, from April 20th until the new community is launched this summer, myibi users should access the TIBCO WebFOCUS page to engage.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] maintain and javascript, trying to limit number of digits

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] maintain and javascript, trying to limit number of digits
 Login/Join
 
Member
posted
Hello,

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, 2009Report This Post
Platinum Member
posted Hide Post
I think you need to test for the value not the value.length.

if (document.adds_sav_fo.Supp_num_sav_Edit.value != " ") {
...test for length...
}

And the 2nd field needs a separate test, not an 'Else'.

Do you also test for numeric input, since you mention digits ?

And I'd work on the error messages too ("only1" ??).


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server
 
Posts: 165 | Location: Detroit Metro | Registered: September 17, 2003Report This Post
Expert
posted Hide Post
Have you tried adding alert statements to see the value and length of the form objects? This should give you a clue why your code does not work.
alert(document.adds_sav_fo.Supp_num_sav_Edit.value);
alert(document.adds_sav_fo.Supp_num_sav_Edit.value.length);

This is how I'd code it:

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 only1");
  }


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Member
posted Hide Post
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, 2009Report This Post
Platinum Member
posted Hide Post
I generally see 3 types of data entry validation:

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.


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server
 
Posts: 165 | Location: Detroit Metro | Registered: September 17, 2003Report This Post
Member
posted Hide Post
thanks. I have tried the blur function and it seems to work with the following:

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");
}


Webfocus Focus
Unix
Windows
 
Posts: 13 | Location: NJ, PA, DE | Registered: March 05, 2009Report This Post
Expert
posted Hide Post
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, 2004Report This Post
Member
posted Hide Post
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, 2009Report This Post
Expert
posted Hide Post
Here's one way:

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);
  }
else
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);
  }
else
  {
  IWCTrigger("run_calc");
  }
}


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
Here's another:

function OnButton9_Click()
{
var tst = 0;

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);
  tst = 1;
  }

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);
  tst = 1;
  }

if (tst == 0)
  {
  IWCTrigger("run_calc");
  }
}

Time for a JavaScript primer? It's fun stuff...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Member
posted Hide Post
yes time for javascript primer Smiler it works great now, thanks for all the help!!


Webfocus Focus
Unix
Windows
 
Posts: 13 | Location: NJ, PA, DE | Registered: March 05, 2009Report This Post
Virtuoso
posted Hide Post
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, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] maintain and javascript, trying to limit number of digits

Copyright © 1996-2020 Information Builders