Able to hide <div> with javascript in Firefox but not IE?

C

cargo303

I have a php page with a drop down list, and the default selected
option is "Select a location" (without quotes).
Using the drop down initiates a database query. One of (3) things
should happen:


1. If an option is selected for which results are available, they
should be displayed on the same page beneath the drop down list in a
table.
2. If an option is selected for which results are NOT available, a
message should be displayed informing the visitor that there were no
results for that query.
3. If the default selected option has not yet been changed (ie: when
the page first loads), no message should display.

#1 and #2 work, but the message described in #2 is still displayed when
the page first loads before the default selected option is changed (#3)
but in Internet Explorer only. Firefox displays the page correctly
under all three conditions.


The message that I want hidden on page load is wrapped in a div named
"infobox" and I'm using the following script to hide it which is at the
bottom of the page:


<script language="javascript" type="text/javascript">

function ClearDiv()
{
if
(document.form2.name.options[document.form2.name.selectedIndex].value=="Select
a location")
{
document.getElementById("infobox").style.display =
"none";
}

}

ClearDiv();
</script>


I've also included the php code that writes out the message and the
table below.

Any help would be appreciated.



<?php
$dbh=mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("USERNAME",$dbh);
$query = "SELECT city, state, station, URL, call_letter, request_line,
phone_line FROM radio_location WHERE state='$_GET[name]' ORDER BY
city";
//echo $query;
$result = mysql_query($query,$dbh);
$resultnum = mysql_num_rows($result);

if ($resultnum == 0) {
echo '<tr id="sorry"><td><div id="infobox">Sorry, there are no radio
stations <br> in' .' ' . $_GET[name].' ' . 'playing Jake\'s
music</div></td></tr>';
}

else {
// CREATE COLUMN HEADINGS
echo "<tr class='search_results_headings'><td width='90px'>City</td><td
width='50px'>Radio Station<td width='50px'>Call Letters<td>URL</td><td
width=90px'>Request Line</td><td width='90px'>Phone Line</td></tr><br
/>";
}
while ($row = mysql_fetch_array($result))
{

// ++++++++++++++++++++++++++++ BUILD THE TABLE ROWS DYNAMICALLY
++++++++++++++++++++++

echo "<tr><td>$row[city]<td>$row[station]<td>$row[call_letter]<td><A
href='http://$row'target='_blank'>$row[URL]</a><td>$row[request_line]<td>$row[phone_line]";

}
echo "<br>";
mysql_close;
?>
</table>
<br />
<?php
 
R

Randy Webb

cargo303 said the following on 5/22/2006 12:04 PM:
I have a php page with a drop down list, and the default selected
option is "Select a location" (without quotes).

I bet your select starts something like this:

<select .....>
<option>Select a location

Test this code in FF and IE:

<select onchange="alert(this.value)">
<option>Option 1
<option value="Option 2">Option 2
<option value="Option 3">Option 3
<option>Option 4
</select>

IE will give blank alerts for Option 1 and 4. There is no value
explicitly defined so IE won't take the options text as the value.

Solution? Give it a value:

<select .....>
<option value="do nothing">Select a location

<script language="javascript" type="text/javascript">

Drop the language attribute.
function ClearDiv()
{
if (document.form2.name.options[document.form2.name.selectedIndex].value=="Select
a location")

if
(document.form2.name.options[document.form2.name.selectedIndex].value==
"do nothing")
{
document.getElementById("infobox").style.display = "none";
}

}

ClearDiv();

window.onload = ClearDiv;
I've also included the php code that writes out the message and the
table below.

What code is on the server is irrelevant to what happens in the browser.
 
C

cargo303

Randy, exactly what I needed to do.

Thanks for not only taking the time to give me a solution, but also to
explain why it works that way.
 
R

Randy Webb

cargo303 said the following on 5/22/2006 1:03 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

BTW, not sure what you meant by "Drop the language attribute"?

<script type="text/javascript">

No language attribute. It is deprecated and can cause problems in some
situations.
 
R

Randy Webb

cargo303 said the following on 5/22/2006 1:20 PM:
Sorry, new to Google Groups.

That is why I posted how to properly quote using Google.
Thanks again for the help and education!

It didn't seem to help any though with regards to quoting :(
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top