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.



Read-Only Read-Only Topic
Go
Search
Notify
Tools
javascript problem
 Login/Join
 
Platinum Member
posted
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, 2004Report This Post
<Shane>
posted
Secret,

Try taking out the semicolon after the last } in your if statement.

Shane
 
Report This Post
Platinum Member
posted Hide Post
Shane :

Thank you for responding. After trying that I still get this error,

Line: 71
Char 1
Error: 'value' is null or is not an object.

It still works with the alerts , when I comment them out it fails.

Bob
 
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004Report This Post
<Shane>
posted
Secret,

Try var compdiv_cd = selobj1.options[j].value;

Shane
 
Report This Post
Master
posted Hide Post
Are you sure it is working this way even with alert?

for (var k=0; k if (compdiv_cd == fileObj[k].value) {

I believe you are missing something here.


WFConsultant

WF 8105M on Win7/Tomcat
 
Posts: 780 | Location: Florida | Registered: January 09, 2005Report This Post
Platinum Member
posted Hide Post
Shane:

That changes the error tor

Line: 71
Char 1
Error: 'options{...}value' is null or is not an object.

the original version worked in the alert.

This is strange.

Any more ideas.

Thank you for responding ,

Bob
 
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004Report This Post
Platinum Member
posted Hide Post
Kamesh:

Somehow my cut and paste got stepped on

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 original

This message has been edited. Last edited by: secret,
 
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004Report This Post
Expert
posted Hide Post
Bob,

selobj1 and fileObj are not variables and should not be declared as var -
selobj1 = document.getElementById('combobox1');
fileObj = document.getElementById('listbox1');

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, 2004Report This Post
Platinum Member
posted Hide Post
Tony:

Thanky you for your response.

I still get the same resutlts. If I comment out the alerts I get this meassage:

Error: 'value' is null or is not an object.

If I uncomment the alerts it works.

Any Ideas?

Thanky You

Bob
 
Posts: 103 | Location: ricmmond va | Registered: September 30, 2004Report This Post
Expert
posted Hide Post
Bob,

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, 2004Report This Post
Virtuoso
posted Hide Post
Secret Bob,

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, 2007Report This Post
Gold member
posted Hide Post
Your getting the elements by the ID, but you don't have an ID specified.

Add the ID to the two select boxes as
<select id=combobox1 name=combobox1 onchange='setdatedflt();'>
...
<select id=listbox1 name=listbox1 onchange='setdatedflt();'>



Windows: WF 7.6.2: SQL Server 2008 R2
 
Posts: 86 | Location: Chicago | Registered: August 03, 2007Report This Post
Gold member
posted Hide Post
don't forget id=calendar1 as well



Windows: WF 7.6.2: SQL Server 2008 R2
 
Posts: 86 | Location: Chicago | Registered: August 03, 2007Report This Post
Platinum Member
posted Hide Post
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, 2004Report This Post
<SomeUsr>
posted
quote:
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.
 
Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic


Copyright © 1996-2020 Information Builders