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

Home Posts Topics Members FAQ

How to use a custom style sheet for IE using JavaScript?

112 New Member
Hi there,

I am not sure if this question comes under Html or javscript....

I have an asp page where I am trying to display/hide few table rows based on a drop down selection. the code is as follows,
Expand|Select|Wrap|Line Numbers
  1.  <table><tr  bgcolor="#f3f3f3">
  2.     <td>School</td>
  3.     <td><select name="selectschool1" id="selectschool1" onchange="changeSchool1();">
  4.     <option value="">Please select a school</option>
  5.     <option value="NUSchool">School A</option>
  6.     <option value="Other">School B</option>
  7.     </select>&nbsp;&nbsp;<font color="red" size="1">*</font> </td>
  8.   </tr>
  9.   <tr  bgcolor="#f3f3f3" id="schoolA" name="schoolA" style="display:none;">
  10.     <td>School A</td>
  11.     <td><select name="schoolAnames" >
  12.                                 <option value=""> Please select a school name</option>
  13.                                 <%
  14.         if not rsSchool.bof then rsSchool.moveFirst
  15.         while not rsSchool.eof
  16.             response.write"<option value=""" & rsSchool("SCHOOL_NAME") & """>" & rsSchool("SCHOOL_NAME") & "</option>"
  17.             rsNuSchool.movenext
  18.         wend
  19.         %>    
  20.                         </select></td>
  21.   </tr>
  22.   <tr  bgcolor="#f3f3f3" id="schoolAmajor" style="display:none;">
  23.     <td>Major</td>
  24.     <td><select name="major1" id="major1">
  25.                                 <option value=""> Please select a major</option>
  26.                                   <% while not rsMajor.eof
  27.                         response.write"<option value=""" & rsMajor("id") & """>" & rsMajor("name") & "</option>"
  28.                         rsMajor.movenext
  29.                     wend %>    
  30.                             </select></td>
  31.   </tr>
  32.   <tr  bgcolor="#f3f3f3" id="schoolB" name="schoolB" style="display:none;" >
  33.             <td> Other School</td>
  34.             <td><input type = "text" name = "schoolBname" id="schoolBname" maxlength="50" size="30" value = ""/></td>
  35.             </td>
  36.   </tr></table>
I am using a javascript to make the display attribute to
block but this does not work in firefox as required. So I found a work around and used this,

Expand|Select|Wrap|Line Numbers
  1. function showSchool(thing) {
  2.         theSection = document.getElementById(thing);
  3.         theSection.style.display = 'block';
  4.     //theSection.style.display = '-moz-inline-table-block';
  5.  
  6. }
  7.  
this did not work in firefox. So I tried to use, visiblity : collapse and visibility : visible but this wont work in IE.
I would like to know if I can use a separate styling for IE and firefox in javscript..I know I can do that if I am using a style sheet for the whole page.. but not sure in java-script. Can somebody please guide me on this....

thank you
Jun 4 '10 #1

✓ answered by acoder

Firefox and others require 'table-row' as mentioned, and IE demands 'block' as is its wont. So to get both to work as expected, use the empty string (default):
Expand|Select|Wrap|Line Numbers
  1. theSection.style.display = '';

5 1746
gits
5,390 Recognized Expert Moderator Expert
you might create seperate css classes and assign the className attribute with JavaScript like:

Expand|Select|Wrap|Line Numbers
  1. node.className = 'yourClass1';
kind regards
Jun 4 '10 #2
Dormilich
8,658 Recognized Expert Moderator Expert
on the other hand you could also use conditional comments to add CSS for IE.
Expand|Select|Wrap|Line Numbers
  1. <!--[if lte IE 7]-->
  2. something for IE less than version 8
  3. <!--[endif]-->
Jun 5 '10 #3
phvfl
173 Recognized Expert New Member
I would personally use the approach suggested by Gits as this provides an nice solution. If you need to set the style directly on the element then you should use the display type "table-row", not "block" for showing the row
Expand|Select|Wrap|Line Numbers
  1. function showSchool(thing) {
  2.          theSection = document.getElementById(thing);
  3.          theSection.style.display = 'table-row';
  4.  }
Jun 5 '10 #4
acoder
16,027 Recognized Expert Moderator MVP
Firefox and others require 'table-row' as mentioned, and IE demands 'block' as is its wont. So to get both to work as expected, use the empty string (default):
Expand|Select|Wrap|Line Numbers
  1. theSection.style.display = '';
Jun 5 '10 #5
user1980
112 New Member
thank you all for the responses....
and the solution to use default for the display style worked....of course I did not try the other ones..as I had to create a new style-sheet which I did not want to...
Anyways, the answer by Acoder worked...

Thank you once again...
Jun 7 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hank Flowers | last post by:
In trying to load a style sheet via JavaScript I ran into a problem...the style sheet doesn't load. This simple task has turned into a vexing problem. Here is the script and html: <html> <head>...
1
by: Aaron Prohaska | last post by:
Does anyone have an idea how to share common include files like a stylesheet or javascript file across multiple web projects in vs.net? Regards, Aaron
9
by: Poker Man | last post by:
Hi, I know how to do Sumbit buttons in Forms, and I know how to do custom buttons in Javascript. What I can't seem to find is how to do custom Submit buttons using Javascript! Anybody out...
0
by: Daniel | last post by:
Does system.xml have any way to transofrm data with an xswl style sheet using strings like MSXML2 does? how to convert this to use System.XML so i do not depend on MSXML2 interop? static...
3
by: boney.dalwani | last post by:
Hello All, I m new to JavaScript and widely Exploring programming in js i have a situation where in i do not want to use alert(message); / prompt(message) kind of functionility. rather i want...
5
by: Rishika14 | last post by:
Hi, Somebody pls tell me how to export data from webpage to excel sheet using java script. rishika
4
by: lilOlMe | last post by:
Hi there! I've run into a bit of a problem wherein a <div> containing an error message is made invisible by an animation. I've tried everything to make this <div> reappear on a button click...
3
by: dileepkms | last post by:
can we disable copy and paste functionality for excel sheet using javascript? if we do it, can you send me the code
2
by: purebuilt | last post by:
Hello all, I have a variable 'css' that reads a url for a style sheet. I need to add the 'css' style sheet to the cascade using JavaScript. Is there a clean way to do that? Thanks. DB
2
by: sanjuindia2005 | last post by:
How can i read the excel sheet using javascript ?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
1
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...
1
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...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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 ...

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.