473,569 Members | 2,984 Online
Bytes | Software Development & Data Engineering Community
+ 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
5 1751
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
2440
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> <title>load a style sheet</title> <script type="text/javascript" language="JavaScript"> var mystyle="css/mystyle.css"; document.write=("<link...
1
1007
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
3984
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 there have any pagesthat might provide a clue?
0
316
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 public string XslTransform(string style, string strdata) { MSXML2.IXMLDOMDocument pDoc = new MSXML2.DOMDocumentClass(); pDoc.async = false;...
3
13504
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 to contruct a custom dailog Box. Is it possible to construct a custom dailog Box using javascript ? if yes, can anybody guide me through the...
5
32877
by: Rishika14 | last post by:
Hi, Somebody pls tell me how to export data from webpage to excel sheet using java script. rishika
4
5149
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 (set the visibility=visible, set the display=block...etc) but nothing seems to be working. I think the animation is setting a <div>'s opacity to 0. (I...
3
2736
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
3083
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
2688
by: sanjuindia2005 | last post by:
How can i read the excel sheet using javascript ?
0
7619
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...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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...
0
6290
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...
0
5228
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...
0
3662
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
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
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
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...

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.