Focal Point
[SOLVED] Preselect dropdown box value for ONE single &variable

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

March 21, 2011, 07:31 PM
mpbMDE
[SOLVED] Preselect dropdown box value for ONE single &variable
There IS now a "selected value" box that you can specify what you would like as the selected/highlighted value in your drop-down box. !IBI.AMP.varname as opposed to DefaultText does NOT work. In fact, I've been trying alternatives I've found here for 2 days now. None of them work. It would make life SOOOO much simpler if an &variable did work there.

Having said that,

Using a fex to create and set default content of the control, how DO I create a list and set the default (WITHOUT movin the default to the top of the list?

Thanks for any help you can provide!!
ps. I am NOT a javascript programmer. I am not afraid to insert a little in there if that works, but need specifics.

This message has been edited. Last edited by: mpbMDE,


WebFOCUS 8.1.05 Windows 7, all output
March 22, 2011, 02:48 AM
Ramkumar - Webfous
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<BASE href=HTTP://localhost:8080>
<SCRIPT id=clientEventHandlersJS type=text/javascript>
function window_onload() {
UpdateData();
document.getElementById("listbox1").selectedIndex = 1;

}

</SCRIPT>

<SCRIPT for=window eventname="onload">window.onload = function() { window_onload(); }</SCRIPT>

<META content="MSHTML 6.00.6000.17095" name=GENERATOR>
</HEAD>
<BODY style="OVERFLOW: auto">
<FORM id=form1>
</FORM>
<SELECT id=listbox1 style="Z-INDEX: 1; LEFT: 270px; WIDTH: 250px; POSITION: absolute; TOP: 110px; HEIGHT: 140px" tabIndex=1 size=3 name=COU datasource="country.fex" displayfield datafield datatype="1" sourcetype="typeFex" ibic_server ibiapp_app="SESSION baseapp" newchainnumber="0">
</SELECT>  
<SPAN id=text1 style="Z-INDEX: 3; LEFT: 200px; WIDTH: 60px; POSITION: absolute; TOP: 130px; HEIGHT: 20px" tabIndex=3>Country 
</SPAN>
</BODY>
</HTML>




Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
March 22, 2011, 02:49 AM
Ramkumar - Webfous
 document.getElementById("listbox1").selectedIndex = 1;


This is the key here. You can change the SelectedIndex value, as needed to say which Item needs to be selected.


Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
March 22, 2011, 12:16 PM
Wep5622
That won't work in 7.6.11. The listbox hasn't finished populating yet when the onload function gets called.

Besides, it is a very rough simplification, it just selects the 2nd item in the listbox, which is not what you want.

Try this (off the top of my head):
function onInitialUpdate() {
    document.getElementById("listbox1").value = "!IBI.AMP.varname;";
}


The important part here is that the code to set the default for the dropdown is in onInitialUpdate(), a function called by the IBI libraries after the contents of the form-elements are loaded (which happens asynchronously since 7.6.10 or so, which just means different parts of the page are downloaded in parallel using multiple connections, but the consequence is that it's not as cut-and-dry when the page has finished loading).

Setting a dropdown boxes' value directly (like I did above) doesn't work in IE6, but it should work in later versions (and other browsers).
If you're cursed with IE6, you'll need to iterate through the list of options in the dropdown box until you find the one with the right value, and set it's "selected"-attribute to some value (doesn't matter what, even "false" means true there).
For help with Javascript, I can recommend the Core Javascript Guide at mozilla.


Also noteworthy, "listbox1" in above example refers to the id-attribute of your dropdown form-element (see the properties panel), not to its name-attribute - that seems to be a common mistake among WebFOCUS users.
And... that attribute has to be unique in your HTML page, of course.


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 :
March 22, 2011, 03:10 PM
mpbMDE
I inserted this:
function onInitialUpdate() {
document.getElementById("combobox1").value = "!IBI.AMP.MYCAR;";
}
into my HTML. Then I get NO values in my dropdown box.

Here is my fex that is populating the dropdown box:
-* File defaultcar.fex
-SET &MYCAR = 'TR7';

TABLE FILE CAR
SUM
FST.MODEL
BY MODEL NOPRINT
WHERE COUNTRY EQ 'ENGLAND';
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE PCHOLD FORMAT XML
END
I want the &MYCAR value selected as the default.
Marilyn


WebFOCUS 8.1.05 Windows 7, all output
March 22, 2011, 03:58 PM
Rob Bowen
I may be mistaken, but if the variable name being used to indicate the default is the same name as the variable that the listbox is also tied to, the listbox should automatically set the value so long as it actually exists in the list.

Since your having issues with this though, I may be wrong.

In any event, the following could be added to the onInitialUpdate() to set the correct item.

var list = document.getElementById('combobox1');
for(var i=0; i<list.length; i++)
{
  if(list[i].value == '!IBI.AMP.VARNAME;')
    list.selectedIndex = i;
}



WebFOCUS 8.1.04; SQL Server 2012; Windows 7; Windows Server 2012 R2;
March 23, 2011, 06:24 AM
Tony A
quote:
In any event, the following could be added to the onInitialUpdate() to set the correct item.

Only if your HTML is called using -HTMLFORM label syntax.

e.g.

-HTMLFORM BEGIN
your html code
-HTMLFORM END

or

-HTMLFORM your_html_filename

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 
March 23, 2011, 10:07 AM
Wep5622
quote:
Originally posted by mpbMDE:
Here is my fex that is populating the dropdown box:
-* File defaultcar.fex
-SET &MYCAR = 'TR7';

TABLE FILE CAR
SUM
...


That's the wrong place to set the default value, you need to do that in the fex that includes your HTML page (where you put -HTMLFORM).


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 :
March 23, 2011, 10:47 AM
mpbMDE
quote:
That's the wrong place to set the default value, you need to do that in the fex that includes your HTML page (where you put -HTMLFORM).


Aha That's why this method doesn't work. The launch page is opened by another application, via the URL. That leaves me with no solution again. Is there a way to do this in the fex that populates the dropdown box? I have seen many variations of the following:
<option value="INTERCEPTOR III">INTERCEPTOR III</option>
<option value="TR7"selected="selected">TR7</option>
<option value="V12XKE AUTO">V12XKE AUTO</option>

They all have slight differeces: spacing, capitaliztion, location and text of the selection phrase.

Anyone know what works in v7.6.11 and the other details I need to implement this?
THANKS!
Marilyn

This message has been edited. Last edited by: mpbMDE,


WebFOCUS 8.1.05 Windows 7, all output
March 24, 2011, 09:26 AM
MAdams1
I don't know if I am off base here, but if you always want the &MYCAR var to be TR7 just hard code it in the HTML page like below;

function onInitialUpdate() {
 
var list = document.getElementById('combobox1');
for(var i=0; i<list.length; i++)
{
  if(list[i].value == 'TR7')
    list.selectedIndex = i;
}
 
}




WebFOCUS Server 8.1.05
Windows 2008 Server
WebFOCUS AppStudio 8.1.05
Windows 7 Professional
IE 11 and Chrome Version 43.0.2357.124 m.
Mostly HTML, PDF, Excel, and AHTML
March 24, 2011, 01:01 PM
mpbMDE
quote:
'TR7'

Thanks MAdams1!!
I did get this to work. I just changed the 'TR7' to '!IBI.AMP.MODEL;'.
The other thing I did was to make the starting object starthere.fex that simply has this in it:
-* File starthere.fex
-SET &MODEL = 'TR7';
-HTMLFORM LAUNCH_CAR.htm
---------------------------
Now all I have to do is get the incoming &MODEL value from the source. The source is in the URL that starts the fex starthere.fex.

Marilyn


WebFOCUS 8.1.05 Windows 7, all output