Javascript undefined in aspx page

D

David C

I have an aspx page with Javascript inside a script block at the end of my
aspx page. I am trying to show or hide 2 tables inside a FormView but I keep
getting the value in Javascript as "undefined" and I cannot understand why.
It occurs when I try to set the value of a variable to one I set at the top
of the page. I have also tried it with getElementById (commented out) and
it gives me the same thing. The variable ssaleleasecode is getting the
undefined message. Can anyone spot the problem? Thanks. Below is the
Javascript code:
David

if ((document.getElementById('fvPropertyClosings_SaleTable') != null) ||
(document.getElementById('fvPropertyClosings_LeaseTable') != null))
var ssaleleasecode = '<%=strLeaseSaleCode %>';
//var obj = document.getElementById('txtSaleOrLease');
//var ssaleleasecode = obj.value;
alert('strLeaseSaleCode=' + ssaleleasecode);
if (ssaleleasecode == 'S')
{
var otbl =
document.getElementById('fvPropertyClosings_SaleTable');
otbl.className = 'Show';
otbl = document.getElementById('fvPropertyClosings_LeaseTable');
otbl.className = 'Hide';
calcpriceper();

}else{
if (ssaleleasecode == 'L')
{
var otbl =
document.getElementById('fvPropertyClosings_LeaseTable');
otbl.className = 'Show';
otbl = document.getElementById('fvPropertyClosings_SalesTable');
otbl.className = 'Hide';
}
}
 
M

Mark Rae [MVP]

Can anyone spot the problem?

If you do a View Source, can you find the object called
fvPropertyClosings_SaleTable? If so, is that only part of the object's
name...?

If so, change your code to e.g.

if ((document.getElementById('<%=fvPropertyClosings_SaleTable.ClientID%>')
!= null) ||

etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top