Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inconsistent response in IF statement 1

Status
Not open for further replies.

jawa500

Programmer
Dec 18, 2002
8
EU
The IF statement checks if a string is empty. If not empty a hyperlink appears on a popup DIV, otherwise the hyperlink should be omitted.

I have attached a piece of cut down code to illustrate the problem.

Follow these steps:

1. Clicking on link A displays a DIV with only a "Close this window" link.

2. Clicking on link B displays a DIV with an "Attached document" link as well as the "Close this window" link.

3. Clicking on link A again displays a DIV with both links where I would only expect the "Close this window" link to appear as the length of arrayObj[1][5] = "".


<html>
<head>
<SCRIPT language= javascript >

var arrayObj = new Array(5);

for (i = 0; i < 3; i++)
arrayObj = new Array(5)

arrayObj[1][0] = 1;
arrayObj[1][1] = &quot;Link A&quot;;
arrayObj[1][2] = &quot;AA&quot;;
arrayObj[1][3] = &quot;AA&quot;;
arrayObj[1][4] = &quot;AA&quot;;
arrayObj[1][5] = &quot;&quot;;

arrayObj[2][0] = 2;
arrayObj[2][1] = &quot;Link B&quot;;
arrayObj[2][2] = &quot;BB&quot;;
arrayObj[2][3] = &quot;BB&quot;;
arrayObj[2][4] = &quot;BB&quot;;
arrayObj[2][5] = &quot;BB&quot;;


function DisplayDiv(ID)
{
td4.innerHTML = arrayObj[ID][4] + '<br><br>';

alert(&quot;String length = &quot; + arrayObj[ID][5].length);

// THIS IF STATEMENT IS INCONSISTENT
if (arrayObj[ID][5].length != 0)
td5.innerHTML = &quot;<a href = 'abc.asp' target='_new'>Attached document</a><br><br>&quot;;

document.all.DivPopUp.style.visibility = &quot;visible&quot;;
}

function HideDiv()
{
document.all.DivPopUp.style.visibility = &quot;hidden&quot;;
}

</SCRIPT>
</head>

<body>
<table border=&quot;0&quot; cellpadding=&quot;4&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot; class=&quot;textBlackSmall&quot;>

<tr>
<td><a href=&quot;javascript:void[0]&quot; onclick=&quot;DisplayDiv(1)&quot;>A</a></td>
</tr>

<tr >
<td><a href=&quot;javascript:void[0]&quot; onclick=&quot;DisplayDiv(2)&quot;>B</a></td>
</tr>

</table>


<div id=&quot;DivPopUp&quot; style=&quot;position:absolute; left : 200px; width : 420px; visibility : hidden; background-color: #ffffcc; &quot; >

<table width = 400 align = &quot;center&quot; border = 0>
<tr valign = &quot;top&quot;>

<td width = 15%><b>Details: </b></td>
<td colspan = 3><div id = 'td4' style=&quot;position: relative; width: 320px; height: 100px; background-color: #ffffff; overflow: auto &quot;> </div></td>

</tr>

<tr>

<td> </td>

</tr>
<tr>

<td colspan = 4 align = &quot;center&quot; id = &quot;td5&quot;> </td>

</tr>

<tr>


<td colspan=4 align=center><a href=&quot;javascript:void[0]&quot;onclick='HideDiv()'>Close this window </td>

</tr>

</table>

</div>

</body>

</html>
 
try throwing in an alert to see what's going on:
Code:
alert( arrayObj[ID][5].length );


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
That's what I tried, see the line before the IF statement.

The lengths were correct, 0, 2, 0 per the three steps.

 
then if zero is the only unacceptable value, try

if (arrayObj[ID][5].length > 0)




=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Thanks but trying > 0 still doesn't work.

 
ok, i think i see what's going on. it's working fine: if you click on A first, the link is not there. the problem is that you're not clearing it after creating it by clicking B - any subsequent clicks on A will show it since it wasn't removed.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Now its obvious.

Putting...

td5.innerHTML = &quot;&quot;;

before the IF statement fixes it.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top