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.

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.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] javascript for a textbox

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] javascript for a textbox
 Login/Join
 
Guru
posted
I am trying to use javascript in a textbox, so that when a user hits enter on leaves the textbox, it fires off the code for a button click. I have many buttons on a page. When a user clicks on a button the color changes and clears out the color for all of the other buttons. That is how I identify the active button to execute.

First question, what event fires off when pressing enter? I believe it is onkeypress('enter') or something like that.

Secong question, I believe I fies off the button onclick event, but what do I put in for the ctrl? (onclick(ctrl))

var b1 = document.getElementById('button1');
var b2 = document.getElementById('button2');
var b3 = document.getElementById('button3');
var b4 = document.getElementById('button4');
var b5 = document.getElementById('button5');
var b6 = document.getElementById('button6');
var b7 = document.getElementById('button7');
var b8 = document.getElementById('button8');
var b9 = document.getElementById('button9');
var b10 = document.getElementById('button10');
var b11 = document.getElementById('button11');
var b12 = document.getElementById('button12');
var b13 = document.getElementById('button13');
var b14 = document.getElementById('button14');
var b15 = document.getElementById('button15');

color = "#4f8df1"

switch (color)

{

case b8.style.backgroundColor:

b8.button8_onclick(ctrl)

break

default:

document.write("Does color ", color , "match " ,

b8.style.backgroundColor , "!")

}

This message has been edited. Last edited by: Jay Potter,


WebFocus 8.1.5
iSeries/Windows
DB2/SQL/Access
Dev Studio
App Studio
Maintain
ReportCaster
 
Posts: 341 | Location: Pembroke NH/Jericho NY | Registered: June 15, 2011Report This Post
Platinum Member
posted Hide Post
Hi Jay,
I may be wrong - but in a "proper" textbox pressing Enter would create a new line.
You could however trap when they leave the textbox with an onblur e.g.
<textarea name="TEXT1" rows="7" cols="70" onBlur="convert()" >

We used this to convert Enters to spaces e.g.
function convert() {
text = document.FORMNAME.TEXT1.value;
text = replace(text,unescape('%0D'),' ');
text = replace(text,unescape('%0A'),'');
document.FORMNAME.TEXT1.value = text;
}
function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length; 
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}
  


Perhaps this gives you some ideas for the first part of your question.


WebFOCUS 8.2.06 mostly Windows Server
 
Posts: 195 | Location: Johannesburg, South Africa | Registered: September 13, 2008Report This Post
Virtuoso
posted Hide Post
quote:
First question, what event fires off when pressing enter? I believe it is onkeypress('enter') or something like that.


Not quite, no. The function in the onkeypress handler gets called with an event-data parameter that contains what key got pressed (among other things).

More details can be found in the reference: https://developer.mozilla.org/...Web/Reference/Events


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Guru
posted Hide Post
You can just chain the text box through the gui to the buttons or whatever you want to show or hide and control that functionality from the parameters page.

The only issue is pressing enter won't unfocus in IE 9. The user will either have to click out or press tab. I don't know about IE10.


WebFOCUS 7.7.03/8.0.08
Dev Studio 7.7.03/8.0.08
App Studio 8.0.08
Windows 7
ALL Outputs
 
Posts: 402 | Location: Upland, IN | Registered: June 08, 2012Report This Post
Guru
posted Hide Post
I have tried the onblur event and have decided I do not want to use that event because it is a lostfocus type ebent and when clicking on a different button it fires off theoriginally selected button first.

I am still trying to identify when the enter button is selected. 'enter' is not working. Do I try and do an IF statement compareing against a 'ctrl' value? Does the onselect methoed fire off when the enter button is pressed?


WebFocus 8.1.5
iSeries/Windows
DB2/SQL/Access
Dev Studio
App Studio
Maintain
ReportCaster
 
Posts: 341 | Location: Pembroke NH/Jericho NY | Registered: June 15, 2011Report This Post
Virtuoso
posted Hide Post
In a textarea, the only events that get fired on pressing the enter key (or any other key) are onkeydown, onkeyup and (the combination of those two) onkeypress.

The first argument to the callback is usually the event object, as in the reference I linked. I don't think IBI is actively intercepting that call to replace it with their own callback, but they do omit passing the event object on to the callback function.

Try chainging the calls into these:
 onkeypress="textarea1_onkeypress(event, this)"

function textarea1_onkeypress(ev, ctrl) {



Here's an example that prints the keyboard character code after the key-press in the textarea (assuming yours has id=textarea1):
function textarea1_onkeypress(ev, ctrl) {
	var dbg = document.getElementById('textarea1');

	dbg.value += "["+ ev.keyCode + "]";
}


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Guru
posted Hide Post
I thank you for all of the replies. I yhink I have found out what I am looking for. I failed to say the the textbox (not textarea) is part of a form. What I will be using is the onsubmit of the form, which fires when the user hits enter.


WebFocus 8.1.5
iSeries/Windows
DB2/SQL/Access
Dev Studio
App Studio
Maintain
ReportCaster
 
Posts: 341 | Location: Pembroke NH/Jericho NY | Registered: June 15, 2011Report 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] javascript for a textbox

Copyright © 1996-2020 Information Builders