473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

make a div visible - works in IE on a pc but not in IE on a mac

Here is a script that is suppose to turn the DIV tag "optionalDiv"
visible on click. This works fine on a PC (IE and Netscape both I
think) but not on a Mac. Why?

<script language="javascript">
document.getElementById('optionalDiv').style.visib ility='hidden';

function makeOptionalDivVisible() {
document.getElementById('optionalDiv').style.visib ility='visible';
document.getElementById('optionalDiv').style.heigh t='auto';
}
</script>

<a href="#" onclick="makeOptionalDivVisible();">More options?</a>
</div>
<div id="optionalDiv" class="optional">
Jul 23 '05 #1
5 4290
Lee
lawrence said:
<a href="#" onclick="makeOptionalDivVisible();">More options?</a>


I don't know if this is the problem, but a browser would
be perfectly correct to call your function, making the
div visible, and then immediately reload the page, making
it hidden again.

If you don't want to load the link specified in the href
attribute (the top of the current page, in the case of "#"),
your onclick handler should return false.

onclick="makeOptionalDivVisible();return false"

Jul 23 '05 #2
Lee <RE**************@cox.net> wrote in message news:<cb*********@drn.newsguy.com>...
lawrence said:
<a href="#" onclick="makeOptionalDivVisible();">More options?</a>


I don't know if this is the problem, but a browser would
be perfectly correct to call your function, making the
div visible, and then immediately reload the page, making
it hidden again.

If you don't want to load the link specified in the href
attribute (the top of the current page, in the case of "#"),
your onclick handler should return false.

onclick="makeOptionalDivVisible();return false"


So, I guess I can fix this by putting in the id name? Like this:
<a href="#optionalDiv" onclick="makeOptionalDivVisible();">More options?</a>
Jul 23 '05 #3
Lee
lawrence said:

Lee <RE**************@cox.net> wrote in message
news:<cb*********@drn.newsguy.com>...
lawrence said:
><a href="#" onclick="makeOptionalDivVisible();">More options?</a>


I don't know if this is the problem, but a browser would
be perfectly correct to call your function, making the
div visible, and then immediately reload the page, making
it hidden again.

If you don't want to load the link specified in the href
attribute (the top of the current page, in the case of "#"),
your onclick handler should return false.

onclick="makeOptionalDivVisible();return false"


So, I guess I can fix this by putting in the id name? Like this:
<a href="#optionalDiv" onclick="makeOptionalDivVisible();">More options?</a>

No. Make the onclick handler return false, so it doesn't
matter what's in the href attribute.

Jul 23 '05 #4
Lee <RE**************@cox.net> wrote in message news:<cb********@drn.newsguy.com>...
lawrence said:

Lee <RE**************@cox.net> wrote in message
news:<cb*********@drn.newsguy.com>...
lawrence said:

><a href="#" onclick="makeOptionalDivVisible();">More options?</a>

I don't know if this is the problem, but a browser would
be perfectly correct to call your function, making the
div visible, and then immediately reload the page, making
it hidden again.

If you don't want to load the link specified in the href
attribute (the top of the current page, in the case of "#"),
your onclick handler should return false.

onclick="makeOptionalDivVisible();return false"


So, I guess I can fix this by putting in the id name? Like this:
<a href="#optionalDiv" onclick="makeOptionalDivVisible();">More options?</a>

No. Make the onclick handler return false, so it doesn't
matter what's in the href attribute.


Sorry I'm so ignorant of Javascript. What does Javascript do when a
function returns nothing? How can returning false affect the behavior
of the browser. I would think that returning false equals "Don't do
anything", and I would assume that is the default behavior when no
return is specified. Apparenlty I'm wrong? Why does returning false
effect browser behavior?
Jul 23 '05 #5
lawrence wrote:
Lee <RE**************@cox.net> wrote in message news:<cb********@drn.newsguy.com>...
Please do not write attribution novels.
lawrence said:
Lee <RE**************@cox.net> wrote [...]
If you don't want to load the link specified in the href
attribute (the top of the current page, in the case of "#"),
your onclick handler should return false.

onclick="makeOptionalDivVisible();return false"

So, I guess I can fix this by putting in the id name? Like this:
<a href="#optionalDiv" onclick="makeOptionalDivVisible();">More options?</a>


No. Make the onclick handler return false, so it doesn't
matter what's in the href attribute.


Sorry I'm so ignorant of Javascript. What does Javascript do when a
function returns nothing?


Nothing :) The value of a function where there is no `return' statement
or that statement is never reached during execution will have a return
value of `undefined', specified in ECMAScript as the sole value of the
Undefined type.
How can returning false affect the behavior of the browser.
Returning a value to an intrinsic event handler can cancel an event
so that the default event action for an element is not performed.
Often this value is `false', sometimes it is `true'. That depends
on the event handler which in turn depends on the DOM of the UA.

Returning `true' to the `onclick' event handler of an element works
as if that element was never clicked (where "click" means the method
used to activate the element, often a mouse click but it can be the
Return key pressed on a focused element, too). For a visible
hyperlink it means, informally speaking, that the "href" attribute
of that element is ignored:

<a href="#" onclick="makeOptionalDivVisible(); return false;"More options?</a>
This can be simplified if the method called already returns `false':

<a href="#" onclick="return makeOptionalDivVisible();"More options?</a>
(However, this link is more often not the right way to do it as it
will be useless for users without client-side script support since
the event handler attribute will be ignored then. The above should
method only be used if the document is accessible only via client-
side scripting. Otherwise, if it is a script-only link that link
should be written dynamically, possibly turned into an CS-styled
"input" element if part of a form. If it is not a script-only link
[and developers should try to create such links], the "href" attribute
should provide a useful alternative for no-client-side-script users
[for example using server-side scripting] while returning `false' to
the "onclick" event handler to prevent users with client-side script
support from seeing that alternative and execute script code instead.)

This way of calling a method in an event handler allows for either
canceling an event or not, depending on other conditions checked
for in the method. A common way of using this technique is client-
side form checking:

<form ... onsubmit="return checkForm(this);">
...
</form>

The checkForm() method should return `false' and thus the event
listener code will return `false' to the handler, if, and only
if, there are some plausibility errors in the form. This will
then prevent the form from being submitted.

If everything in the form is OK, the method should return `true',
returning `true' to the intrinsic event handler in turn which
allows the UA to perform the default action for the "submit"
event of the "form" element which is, of course, to submit the
form. (Note that client-side form checking cannot replace
server-side form checking as the event handler code will be
never executed with having client-side script support absent
or disabled. But the *additional client-side checking can
help to avoid round trips and thus reduce both network and
server load.)
I would think that returning false equals "Don't do anything",
Yes, but if, and only if, `false' is returned to the event handler
and the event handler regards `false' as the cancel value.
and I would assume that is the default behavior when no
return is specified. Apparenlty I'm wrong?


Yes. Not returning anything to the event handler results in the
default behavior: First the event handler executes user-defined
code for the event (the event listener), then the default action
for the element is performed.
HTH

PointedEars
Jul 23 '05 #6

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

Similar topics

1
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if...
3
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is...
6
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
16
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images,...
2
by: Jake Barnes | last post by:
Imagine I've this block of HTML: <p>Alex Schein Mailing List <input type="checkbox" name="newslettersToUse" value="133156"> (<a href="mcControlPanel.php"...
11
by: Jo | last post by:
Hi all, I have a gridview displaying a dataset and some buttons. When a certain cell of this datasetrow is empty, I want a button in that row to be visible, otherwise no button should be shown...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
8
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx...
5
by: Jan | last post by:
Hello, Just after the new record is inserted in the database using a Detailsview control, i would like to display a short message "the record is inserted". In the aspx file, i defined a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.