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.
Below is a javascript function that populates a calendar control with a default date from a hidden lisbox depending on the users selection from a combobox. The code works as is. The problem is if I remove or comment out all the alerts it produces an object error. Can anyone explain this. It's driving me crazy.
//-------------------------------------------------------------
// this function matches the compdiv in the comdiv combobox to the hidden listbox1
// to retieve the default start date for that company.
// different companies have different load dates.
// The listbox1 control is hiddden and loaded by the IBI.fil method. this form is called by
// the franchise_sales_date_default.fex. This fex extracts the companies and dates from a view
// and diplays the htlmform.
//-------------------------------------------------------------
function setdatedflt() {
//-------------------------------------------------------------
var selobj1 = document.getElementById('combobox1');
var i = document.getElementById('combobox1').selectedIndex;
// set to select first occurance if not selected = 0)
// set index to zero if not selected
if (i == -1) {
var j = 0;
} else {
var j = i;
};
alert("the value of j is" + " " + j);
alert("the value is" + " " + selobj1[j].value);
var compdiv_cd = selobj1[j].value ;
var fileObj = document.getElementById('listbox1') ;
for (var k=0; k<fileObj.length; k++){
if (compdiv_cd == fileObj[k].value) {
alert("the text is" + " " + fileObj[k].text);
document.getElementById('calendar1').value = fileObj[k].text;
}
}
}
This message has been edited. Last edited by: secret,
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004
Here is the for statement. I have edited the original text the caret in the for was causing a problem, I used the code /code to fix the originalThis message has been edited. Last edited by: secret,
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004
Are you sure that the combobox is giving you an array? If not then do not use selobj1[j].value, just use selobj1.value as that should be populated for you from the selectedIndex pointer.
Not sure why the alerts would actually make that work though.
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, 2004
May be the problem originates somewhere else entirely. I have created the following html file, using your code, and it runs fine on my environment (which is IE6 at the moment). Please try this html file on your end and see if it runs ok.
<HTML>
<head>
<script language=javascript>
//-------------------------------------------------------------
// this function matches the compdiv in the comdiv combobox to the hidden listbox1
// to retieve the default start date for that company.
// different companies have different load dates.
// The listbox1 control is hiddden and loaded by the IBI.fil method. this form is called by
// the franchise_sales_date_default.fex. This fex extracts the companies and dates from a view
// and diplays the htlmform.
//-------------------------------------------------------------
function setdatedflt() {
//-------------------------------------------------------------
var selobj1 = document.getElementById('combobox1');
var i = document.getElementById('combobox1').selectedIndex;
// set to select first occurance if not selected = 0)
// set index to zero if not selected
if (i == -1) {
var j = 0;
} else {
var j = i;
};
//alert("the value of j is" + " " + j);
//alert("the value is" + " " + selobj1[j].value);
var compdiv_cd = selobj1[j].value ;
var fileObj = document.getElementById('listbox1') ;
for (var k=0; k<fileObj.length; k++){
if (compdiv_cd == fileObj[k].value) {
//alert("the text is" + " " + fileObj[k].text);
document.getElementById('calendar1').value = fileObj[k].text;
}
}
}
</script>
</head>
<body>
<form name=xx>
<select name=combobox1 onchange='setdatedflt();'>
<option value=cd1>code 1</option>
<option value=cd2>code 2</option>
<option value=cd3>code 3</option>
<option value=cd4>code 4</option>
<option value=cd5>code 5</option>
<option value=cd6>code 6</option>
<option value=cd7>code 7</option>
</select><br><br>
<select name=listbox1 size=8>
<option value=cd1>code value = 1</option>
<option value=cd2>code value = 2</option>
<option value=cd3>code value = 3</option>
<option value=cd4>code value = 4</option>
<option value=cd5>code value = 5</option>
<option value=cd6>code value = 6</option>
<option value=cd7>code value = 7</option>
<option value=cd8>code value = 8</option>
</select><br><br>
<input type=text name=calendar1 value='unknown'>
</form>
</body>
</html>
Hope this helps....
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007
I solved the problem by loading the calendar from a procedure. The function worked from the onchange event of combo1. It did not work from the window onload event. When I added an alert to the onload event it worked.
It seems to me that the onload event is being executed before the objects are created , if that makes any sense. by adding the alert I slowed down the execution and it worked.
Thank you for your response.
Bob
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004
It seems to me that the onload event is being executed before the objects are created , if that makes any sense. by adding the alert I slowed down the execution and it worked.
Yes that can happen and can be the downside to using alerts for JavaScript debuging. Normally they are fine, but it can cause problems at times.
Another way to fix this is to change your function to make sure the object you need in the web broswer DOM is ready...
//-------------------------------------------------------------
// this function matches the compdiv in the comdiv combobox to the hidden listbox1
// to retieve the default start date for that company.
// different companies have different load dates.
// The listbox1 control is hiddden and loaded by the IBI.fil method. this form is called by
// the franchise_sales_date_default.fex. This fex extracts the companies and dates from a view
// and diplays the htlmform.
//-------------------------------------------------------------
function setdatedflt() {
//-------------------------------------------------------------
var selobj1 = document.getElementById('combobox1');
if (selobj1)
{
var i = document.getElementById('combobox1').selectedIndex;
// set to select first occurance if not selected = 0)
// set index to zero if not selected
if (i == -1) {
var j = 0;
} else {
var j = i;
};
//alert("the value of j is" + " " + j);
//alert("the value is" + " " + selobj1[j].value);
var compdiv_cd = selobj1[j].value ;
var fileObj = document.getElementById('listbox1') ;
for (var k=0; k<fileObj.length; k++){
if (compdiv_cd == fileObj[k].value) {
//alert("the text is" + " " + fileObj[k].text);
document.getElementById('calendar1').value = fileObj[k].text;
}
}
} else { setTimeout("setdatedflt();", 1000); }
}
The addition was to perform an if check on selobj1 to make sure it was available (in the web broswer DOM), if so... run the code; if not... wait about a second and retry.