Focal Point
[CLOSED]How to code javascript for comobox onchange?

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

February 03, 2017, 09:03 AM
EdHou
[CLOSED]How to code javascript for comobox onchange?
I have four Html launch pages. Now, I want to create the main launch page to let user to select from a drop down box, which is a combobox. From “Requests & Data sources”, I have 4 Html there. In “Tasks & Animations”, I have “task2 Selection Changed comobox1 HTML File/xxxxx window” there, and task3, task4, task5 are similar with task2.

In “Embedded JavaScript/CSS”, I have “function comobox1_onchange(event)…” However, I think the Javascript I copied is not right, it’s not working. If any of you are javascript expert, please let me know how to code in “Embedded JavaScript/CSS” to make drop down box work. Thank you a lot.

This message has been edited. Last edited by: EdHou,
February 03, 2017, 12:32 PM
EdHou
Please let me know, Thanks.

function combobox1_onchange(event) {
var eventObject = event ? event : window.event;
var ctrl = eventObject.target ? eventObject.target : eventObject.srcElement;
// TODO: Add your event handler code here
var selValue = IbComposer_getCurrentSelection('combobox1');
for(var i = 0; i < combobox1_onchange.length; i++){

if (selValue == 'First Report' && combobox1[i].checked) {
IbComposer_triggerExecution('task2',1);
} else if (selValue == 'Second Report' && combobox1[i].checked) {
IbComposer_triggerExecution('task3',1);
}else if (selValue == 'Third Report' && combobox1[i].checked) {
IbComposer_triggerExecution('task4',1);
}else if (selValue == 'Fourth Report' && combobox1[i].checked) {
IbComposer_triggerExecution('task5',1);

}
}
}
//End function combobox1_onchange


WebFOCUS 8.0.09
WebFOCUS 7.7.05
DBMS: Oracle 11g
all output (Excel, HTML, PDF)
February 05, 2017, 03:49 PM
Waz
I would suggest using the browsers developer tools to track the execution.

As a minimum, add in console.log or alert to see where the flow is going.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

February 06, 2017, 04:12 AM
Tony A
The fact that you state that you "copied" some JavaScript leads me to believe that you do not know any JavaScript?

If that is the case then I would really urge you to try and learn it. Look at some sites such as W3Schools.com for some tutorials. You will benefit from it if you are going to be developing similar processes!

If I understand you correctly, you want to trigger a call to the internal "IbComposer_triggerExecution" function to initiate a task that you have built within the GUI, depending upon what the user has selected within a drop down list?

If that is the case then I would suggest using the ability of having the value within the drop down list declared as a procedure - which (providing you get it correct) should trigger the procedure as you need. There have been topics on this before on the Forum.

Alternatively, you could use a case statement like the following -
function combobox1_onchange(event) {
  var eventObject = event ? event : window.event;
  var ctrl = eventObject.target ? eventObject.target : eventObject.srcElement;
// TODO: Add your event handler code here

  switch(document.getElementById("combobox1").selectedIndex) {
    case 0:
      IbComposer_triggerExecution('task2',1);
      break;
    case 1:
      IbComposer_triggerExecution('task3',1);
      break;
    case 2:
      IbComposer_triggerExecution('task4',1);
      break;
    case 3:
      IbComposer_triggerExecution('task5',1);
      break;
    default:
      IbComposer_triggerExecution('task2',1);
  }
}
//End function combobox1_onchange

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 
February 06, 2017, 03:12 PM
EdHou
Waz and Tony, Thank you for your reply.

Yes, Tony, I want the user has selected within a drop down list for any one of the html.

Not working yet. I’ll continue to try.
February 07, 2017, 09:28 AM
EdHou
I like to make a selection from the drop-down, and then click on the ‘Submit’ button to run the report.

This is working now:

function button1_onclick(event) {
var eventObject = event ? event : window.event;
var ctrl = eventObject.target ? eventObject.target : eventObject.srcElement;
// TODO: Add your event handler code here


switch(document.getElementById("combobox1").selectedIndex) {
// switch(document.getElementById("combobox1").focus()) {
case 0:
IbComposer_triggerExecution('task2',1);
event.stopImmediatePropagation();
return;
case 1:
IbComposer_triggerExecution('task3',1);
event.stopImmediatePropagation();
return;
case 2:
IbComposer_triggerExecution('task4',1);
event.stopImmediatePropagation();
return;
case 3:
IbComposer_triggerExecution('task5',1);
event.stopImmediatePropagation();
return ;
default:
IbComposer_triggerExecution('task2',1);
}
}
//End function button1_onclick

Thank you again.
February 07, 2017, 02:21 PM
Waz
EdHou, please update the title of your first post to include [SOLVED] or [CLOSED]


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

February 07, 2017, 03:26 PM
EdHou
Thank you for the reminder, Waz.