Web Analytics Made Easy -
StatCounter from javascript to css - CodingForum

Announcement

Collapse
No announcement yet.

from javascript to css

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • from javascript to css

    I need to change this javascript into a css file and make it function like it is now but I don't want to have javascript enabled on the web browser. Can someone help me?

    <script type="text/javascript">
    function SelectSize()
    {
    var dropDown=document.getElementById("size");
    var SelectedSize = dropDown.options[dropDown.selectedIndex].value;
    document.body.style.fontSize=SelectedSize + "px";
    }
    </script>
    <form name="frmcontrol">
    <select id=size onChange="SelectSize()" >
    <option value="20">Default
    <option value="12">Very Small
    <option value="72">Very Large
    </select>
    <input type="button" value="Change Size of Text" name="myButton" onClick="SelectSize()" />
    </form>

    <script language="javascript">

    function colorChange()
    {
    document.bgColor=document.list.colors.options[document.list.colors.selectedIndex].value;
    }
    </script>
    <form name="list">
    <select name="colors">
    <option value="006633">Default
    <option value="black">Black
    <option value="white">White
    </select>
    <input type="button" value="Change Background color" name="myButton2" onClick="colorChange()" />
    </form>

    <BODY bgColor=#006633>

    <script language="javascript">

    function change()
    {
    document.fgColor=document.text.color.options[document.text.color.selectedIndex].value;
    }
    </script>
    <form name="text">
    <select name="color">
    <option value="black">Default
    <option value="black">Black
    </select>
    <input type="button" value="Change Text color" name="myButton3" onClick="change()" />
    </form>

  • #2
    quite simply, you cant.

    css and javascript arent either/or things, they're completely different.

    You can create different style sheets to use on your page but you would still need javascript to switch between them.
    http://www.hazelryan.co.uk

    Comment


    • #3
      I think he is just looking to imitate a javascript menu with CSS.
      Once I thought I was wrong but I was mistaken.

      Comment


      • #4
        Originally posted by Tristan Gray
        I think he is just looking to imitate a javascript menu with CSS.
        ... its not a javascript menu, its a javascript style switcher that changes text size, colour and bg colour.
        http://www.hazelryan.co.uk

        Comment


        • #5
          Yeah... I just assumed it was like a horizontal menu or something. Well maybe he is looking for how to make the correspondent CSS files to make the style switcher work? heh.
          Once I thought I was wrong but I was mistaken.

          Comment


          • #6
            He could have different style sheets for each style, but that would still require javascript.
            markaylward.co.uk

            Comment


            • #7
              Originally posted by jstewie
              I need to change this javascript into a css file and make it function like it is now but I don't want to have javascript enabled on the web browser. Can someone help me?
              To sum up the above, CSS affects style while Javascript affects behavior. Do you want something fantastic to happen when you click on, say, a div? Use Javascript. Want part of the page be aligned to the right and colored burgundy? Use CSS.
              drums | web

              Comment


              • #8
                I'm trying to be able to change the color of the text as well as the background color and the size of the font - which the javascript does.
                I just found out I can't use javascript, I need to use css files instead and I know nothing about css files. I need the javascript written in css format. I can't use any javascript.

                Comment


                • #9
                  Yeah, I haven't done enough of this sort of thing to be much help but it is as I said. He wants to know how to make the javascript change css attributes like the background colour.


                  Well until you tell us what you want the pages to look like it is going to be bloody hard for us to do much about it. Do a google search for CSS tutorial and learn the basics or show us what you want the pages to look like and someone can probably code the different css files for you.
                  Once I thought I was wrong but I was mistaken.

                  Comment


                  • #10
                    Originally posted by jstewie
                    I can't use any javascript.
                    Then you cant do what you want to do.

                    CSS can only SET the style of the elements on your page, it cannot CHANGE the style, you need javascript for that.

                    You can use CSS to make the page look the way you want it to look. But it will always look that way until you change the style sheet manually.

                    The closest you could come to being able to do what your code does is to use a server side language to dynamically write the style sheet but it would require refreshing the page... for example, your drop down boxes would be in a form that sent the information to itself then php or asp would write the stylesheet based on the input from the form
                    http://www.hazelryan.co.uk

                    Comment


                    • #11
                      Man I need more sleep. I didn't even notice that he said he can't use any javascript. *sigh*

                      Yeah, you can't do it.
                      Once I thought I was wrong but I was mistaken.

                      Comment

                      Working...
                      X