Focal Point
Add 'title' Attribute to Anchor Tag Created By Stylesheet Javascript Parm.

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8671017632

July 12, 2007, 05:52 PM
David Briars
Add 'title' Attribute to Anchor Tag Created By Stylesheet Javascript Parm.
Greetings,

I'd like to add a 'tool tip' to a link created by the FOCUS Stylesheet JAVASCRIPT parameter.

I am creating an HTML table:

  
TABLE FILE CAR
PRINT COUNTRY
ON TABLE SET STYLE *
TYPE=DATA, FIELD=COUNTRY,
 JAVASCRIPT=runCAR(COUNTRY), WHEN=COUNTRY EQ 'JAPAN',$
ENDSTYLE
ON TABLE HOLD FORMAT HTMTABLE AS MYPAGE
END
-RUN


And then embedding the table into a HTMLFORM:

  
-HTMLFORM BEGIN
<html>
<head>
<script  language=Javascript>
function runCAR() {
 alert('hello world');
}
</script>
</head>
<BODY>
 !IBI.FIL.MYPAGE;
</body>
</html>
-HTMLFORM END


If I was creating the anchor tag by hand, I would add the 'title' attribute, like this:

  
<A HREF="javascript:runCAR('JAPAN');" title="Hello World">JAPAN</A>


Is there a way to add a title attribute to an anchor tag created by WebFOCUS?

Regards,
Dave
July 13, 2007, 03:30 AM
Tony A
David,

Not exactly, but you could use a little trickery to achieve what you require. Replace your drilldown code with the following.
 JAVASCRIPT=runCAR(COUNTRY ');" title="Hello World"'), WHEN=COUNTRY EQ 'JAPAN',$

I have tested this on 7.1.3 and it does work Smiler but the drilldown doesn't due to a javascript error Frowner

You might be able to play with this further to get what you need?

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 
July 13, 2007, 03:58 AM
Tony A
Ok, got this to work by extending the code. inclusion within the drilldown code didn't work - it kept dropping the extended stuff - so I placed it into a define instead and not only does the link work but also the title -
DEFINE FILE CAR
  COUNTRY_DRILL/A100 = COUNTRY || ''');"' || ' title="Hello World" x="(''';
END
TABLE FILE CAR
PRINT COUNTRY
      COUNTRY_DRILL NOPRINT
ON TABLE SET STYLE *
TYPE=DATA, FIELD=COUNTRY,
 JAVASCRIPT=runCAR(COUNTRY_DRILL), WHEN=COUNTRY EQ 'JAPAN',$
ENDSTYLE
ON TABLE HOLD FORMAT HTMTABLE AS MYPAGE
END
-RUN
  
-HTMLFORM BEGIN
<html>
<head>
<script  language=Javascript>
function runCAR() {
 alert('hello world');
}
</script>
</head>
<BODY>
 !IBI.FIL.MYPAGE;
</body>
</html>
-HTMLFORM END

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 
July 13, 2007, 09:58 AM
David Briars
Thank you, Tony, for the idea of constructing part of the anchor tag with a DEFINE.

My real situation is a bit more complicated than my example. I am passing many fields from my database to the JavaScript function.

For example:

  
TABLE FILE CAR
PRINT COUNTRY
      CAR
ON TABLE SET STYLE *
TYPE=DATA, FIELD=COUNTRY,
   JAVASCRIPT=runCAR(COUNTRY CAR), WHEN=COUNTRY EQ 'JAPAN',$
ENDSTYLE
ON TABLE HOLD FORMAT HTMTABLE AS MYPAGE
END
-RUN

-HTMLFORM BEGIN
<html>
<head>
<script  language=Javascript>
function runCAR(COUNTRY, CAR) {
 alert('hello ' + COUNTRY + ', you drive a ' + CAR);
}
</script>
</head>
<BODY>
 !IBI.FIL.MYPAGE;
</body>
</html>
-HTMLFORM END
-EXIT


Therefore, if I can, I'd like to avoid constructing my anchor tag.

I wonder if I could name my anchor tag, and then 'set' the title in JavaScript?

Regards,
Dave
July 13, 2007, 01:29 PM
Lucas
Ok I have tested this one. It is kind of backhanded but it works.

DEFINE FILE CAR                                              
STARTA/A30 = '<A HREF='||''''||'javascript:RUNCAR("';        
MIDA/A5 = '", "';                                            
FINISHA/A25 = '")'||''''||' TITLE="HELLO WORLD">';           
CLOSEA/A4= '</A>';                                           
CNTRY/A100=IF COUNTRY EQ 'JAPAN' THEN                        
          STARTA|COUNTRY|MIDA|CAR|FINISHA|COUNTRY|CLOSE      
          ELSE COUNTRY;                                      
END                                                          
TABLE FILE CAR                                               
PRINT CNTRY                                                  
      CAR                                                    
-*ON TABLE SET STYLE *                                       
-*TYPE=DATA, FIELD=COUNTRY,                                  
-*JAVASCRIPT=RUNCAR(COUNTRY CAR) , WHEN=COUNTRY EQ 'JAPAN',$ 
-*ENDSTYLE                                                   
ON TABLE PCHOLD FORMAT HTMLABLE AS MYTHING                   
END                                                          
-RUN                                                         
-HTMLFORM BEGIN                                              
<HTML>                                                       
<HEAD>                                                       
<SCRIPT  LANGUAGE=JAVASCRIPT>                                
function RUNCAR(COUNTRY, CAR) {                              
 alert('HELLO ' + COUNTRY + ', YOU DRIVE A ' + CAR);         
}                                                            
</SCRIPT>                                                    
</HEAD>                                                      
<BODY>                                                       
 !IBI.FIL.MYPAGE;                                            
</BODY>                                                      
</HTML>                                                      



7.6.6 Mainframe
7.6.4 Web Focus
Windows

July 13, 2007, 04:17 PM
Alan B
If you want to use js, this is a starting point:
TABLE FILE CAR
PRINT COUNTRY
      CAR
COMPUTE TITLE_TEXT/A50 = ('This is a '|CAR)||(' from '| COUNTRY); NOPRINT
ON TABLE SET STYLE *
TYPE=DATA, FIELD=COUNTRY,
   JAVASCRIPT=runCAR(COUNTRY CAR TITLE_TEXT), WHEN=COUNTRY EQ 'JAPAN',$
ENDSTYLE
ON TABLE HOLD FORMAT HTMTABLE AS MYPAGE
END
-RUN

-HTMLFORM BEGIN
<html>
<head>
<script  language=Javascript>
function runCAR(COUNTRY, CAR) {
 alert('hello ' + COUNTRY + ', you drive a ' + CAR);
}
function addTitles(){
var i=0;var s='';var t='';var u='';var p='';var q='';var r='';
// Get an array of all the 'a' tags in the document.
var allAnchor = document.getElementsByTagName("a");
// How many 'a' tags are there
var numAnchors = allAnchor.length;
// Loop through all the a tags
for (i=0;i<numAnchors;++i) {
// get the href within the a tag
 t=allAnchor[i].getAttribute("href");
// if this is not a call to runCAR, ignore
  if (t.indexOf("runCAR") < 1) continue;
// substring the href to get the call to the function
// get start of parameters
 s=t.indexOf("(")+1;
// get end of parameters
 u=t.indexOf(")");
// substring
 p=t.substring(s,u);
// put parameters into array
 q=p.split("'");
// get array length, -2 for start and 0 start
 r=q.length-2;
// add title attribute to anchor as last parameter, item r in array q
  allAnchor[i].setAttribute('title',q[r]);
  }
}
window.onload=addTitles;
</script>
</head>
<body>
 !IBI.FIL.MYPAGE;
</body>
</html>
-HTMLFORM END
-EXIT



Alan.
WF 7.705/8.007
July 16, 2007, 02:54 AM
Tony A
Nice solution Alan, but the title text is being shown (in 7.1.3 using IE6) escaped, so they might want to change the title attribute assignment to -
  allAnchor[i].setAttribute('title',unescape(q[r]));

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 
July 16, 2007, 09:40 AM
mgrackin
Sometimes we try to kill a fly with a sledgehammer because we cannot see the easy way to do something. This seems like one of those times. Would it not be easier just to handle the entire task in the DEFINE?

DEFINE FILE CAR
COUNTRY_DRILL/A100 =
IF (COUNTRY NE 'JAPAN') THEN COUNTRY ELSE
'<A HREF="java_script:runCAR[''' | COUNTRY | ''');" title="Hello World">' | COUNTRY | '</A>';
END
TABLE FILE CAR
PRINT COUNTRY_DRILL
ON TABLE HOLD FORMAT HTMTABLE AS MYPAGE
END
-RUN

-HTMLFORM BEGIN
<html>
<head>
<script language=Javascript>
function runCAR() {
alert('hello world');
}
</script>
</head>
<BODY>
!IBI.FIL.MYPAGE;
</body>
</html>
-HTMLFORM END

JMHO


Thanks!

Mickey

FOCUS/WebFOCUS 1990 - 2011
July 16, 2007, 10:33 AM
Tony A
That's true Mickey, but my initial attempt was trying to keep it within the drilldown function itself. Alan's version uses a bit of dynamic HTML via JavaScript and yours uses the old belt and braces approach.

So we've achieved something, and that is to show that there are many ways to crack a nut (kill a fly? skin a cat? peel a prawn?) thereby keeping the mind open to all possibilities.

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 
July 16, 2007, 12:02 PM
Alan B
Ah Yes Tony.

Should have tested the js a bit, unescape is correct.

And as you say, no one solution is perfect for all, otherwise life would be boring.


Alan.
WF 7.705/8.007
July 18, 2007, 09:23 AM
David Briars
Thank you for the set attribute technique, Alan B. This meets my requirements exactly; I have already incorporated it into my development code.

Many thanks to the other contributors to this topic. I appreciate you adding to the discussion.




Pilot: WebFOCUS 8.2.06 Test: WebFOCUS 8.1.05M Prod: WebFOCUS 8.1.05M Server: Windows Server 2016/Tomcat Standalone Workstation: Windows 10/IE11+Edge Database: Oracle 12c, Netezza, & MS SQL Server 2019 Output: AHTML/XLSX/HTML/PDF/JSCHART Tools: WFDS, Repository Content, BI Portal Designer & ReportCaster