473,698 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="javas cript" type="text/javascript">

function ClearDiv()
{
if
(document.form2 .name.options[document.form2. name.selectedIn dex].value=="Select
a location")
{
document.getEle mentById("infob ox").style.disp lay =
"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_conn ect ("localhost" , "USERNAME", "PASSWORD") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("USERNAME",$db h);
$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($qu ery,$dbh);
$resultnum = mysql_num_rows( $result);

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

else {
// CREATE COLUMN HEADINGS
echo "<tr class='search_r esults_headings '><td width='90px'>Ci ty</td><td
width='50px'>Ra dio Station<td width='50px'>Ca ll Letters<td>URL</td><td
width=90px'>Req uest Line</td><td width='90px'>Ph one Line</td></tr><br
/>";
}
while ($row = mysql_fetch_arr ay($result))
{

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

echo "<tr><td>$r ow[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 5100
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>Selec t a location

Test this code in FF and IE:

<select onchange="alert (this.value)">
<option>Optio n 1
<option value="Option 2">Option 2
<option value="Option 3">Option 3
<option>Optio n 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="javas cript" type="text/javascript">
Drop the language attribute.
function ClearDiv()
{
if (document.form2 .name.options[document.form2. name.selectedIn dex].value=="Select
a location")
if
(document.form2 .name.options[document.form2. name.selectedIn dex].value==
"do nothing")
{
document.getEle mentById("infob ox").style.disp lay = "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.javas cript 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.c om, 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.javas cript 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.javas cript 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
4462
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"; } else if (nn6) {
9
3140
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
12184
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 { display: none; }
3
3809
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" onclick="__doPostBack('SitesRadioButtonList_3','')" language="javascript" />
8
104042
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 = "More random text."; </script> <div id="div1">
1
13645
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; background:red">moving</div> and javascript code is: ...
28
5358
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 </p>s included as well. <P>aaaaaaaaa</p><DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</p></DIV>
5
4909
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"; document.getElementById(it).style.display = vis; } </script> I have a checkbox to hide the <div> when checked:
8
10041
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 editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a state where it almost passes the W3C Markup Validation Service. However, the one error, Error Line 166,...
0
8600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8890
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8858
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7711
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5859
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.