473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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[url]'target='_blank'>$row[url]</a><td>$row[request_line]<td>$row[phone_line]";

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

May 22 '06 #1
6 5071
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

<snip>
<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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 22 '06 #2
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.

May 22 '06 #3
BTW, not sure what you meant by "Drop the language attribute"?

May 22 '06 #4
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.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 22 '06 #5
Sorry, new to Google Groups.
Thanks again for the help and education!

May 22 '06 #6
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 :(

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: benzwt | last post by:
I use the following function to hide a <div> named one. function hideObject() { if (ns4) { document.n1.visibility = "hide"; } else if (ie4) { document.all.style.visibility = "hidden"; }...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
2
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
8
by: Primal-oooze | last post by:
In most newer browsers, would the following methods successfully write to the <div>s below? ------ <script> document.all.div1.innerText = "Some random text."; document.all.div2.innerHTML =...
1
by: hitsmly | last post by:
Hi All! I used the following code to move a <div> in IE browser to the position of the mouse when I click on a link +div tag is: <div id=fm style="position:absolute; width:100px; height:100px;...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
5
by: widevision7 | last post by:
I have a web site that uses the following JavaScript to hide <div> sections: <script type="text/javascript"> function showMe (it, box) { var vis = (box.checked) ? "block" : "none";...
8
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.