Top.Mail.Ru
? ?
Javascript's Journal
 
[Most Recent Entries] [Calendar View] [Friends View]

Monday, November 28th, 2005

Time Event
9:31a
Javascript and CSS - hiding elements
Spent some time looking for this last night, but right now I have to get another function working.

When hiding elements with "inline" and "none", the script I normally use requires
style="display:inline;" in the element.


However, the elements I am hiding this time are HTML table cells. Having the style tag seems to mess up the way it draws on FIreFox.

Is there a way to switch classes and hide elements? Seems that if I use a class instead of style it draws nicely.

This is the code I have now, but it doesnt seem to work - but there are no JS errors.
document.getElementById(LayerName).className = "layershow";



Solution:
Even though we got the right code for using classes, ultimately I had to go back to the style tag because of browser draw issues. using the style tag on a nested div tag seems to work.
2:07p
Counting Charcters follow up
The reason for counting characters is to limit the number of characters... so when the count reaches 400, I put up an alert explaining the user has reached the limit.

However, because I am using onkeypress to count the characters, it still "works" when the Javascript error is up. That then results in the is error in FireFox:

Error: uncaught exception: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIDOMTreeWalker.nextNode]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: chrome://global/content/bindings/button.xml :: fireAccessKeyButton :: line 93" data: no]

My first thought was to trim the message. Didn't work.

My second thought was to kick the cursor out of the text box with blur.
if(size > 400)
{
gID("MESSAGE").value = gID("MESSAGE").value.substring(0,399);
gID("MESSAGE").blur();
alert("During Beta Testing Messages are limited to 400 characters. Your message is "+size+" characters long.");
}


But that doesnt seem to work. Any ideas?

BTW: the PHP does also trims the content - so the issue is just the UI and Javascript error, not the function.



Solution: Apparently there is a bug in FireFox 1.0.7 Mac that allows onkeypress to continue to work while the alert dialog is displayed. Disabling the text box before the alert, and then re-enabling it after the alert works. It also looks pretty slick. I'll probably do this anytime I have an alert regarding a form.

<< Previous Day 2005/11/28
[Calendar]
Next Day >>
About LiveJournal.com
Image