Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:19:09+00:00 2026-06-17T14:19:09+00:00

I want to create a script where a user can set the gradient of

  • 0

I want to create a script where a user can set the gradient of a div by inputting color codes in two different text fields.

This is my code:

        <style>
        #gradient {
            background: #0A284B;
    background: -webkit-gradient(linear, left top, left bottom, from(#0A284B), to(#135887));
    background: -webkit-linear-gradient(#0A284B, #135887);
    background: -moz-linear-gradient(top, #0A284B, #135887);
    background: -ms-linear-gradient(#0A284B, #135887);
    background: -o-linear-gradient(#0A284B, #135887);
    background: linear-gradient(#0A284B, #135887);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0A284B', endColorstr='#135887');
    zoom: 1;    }  
    </style>


    <script>

    function myFunction()
    {
    color1 = document.getElementById("color1").value;
    color2 = document.getElementById("color2").value;

    document.getElementById("gradient").style.background="-webkit-gradient(linear, left top, left bottom, from("+color1+"), to("+color2+"))";
    document.getElementById("gradient").style.background="-webkit-linear-gradient("+color1+", "+color2+")";
    document.getElementById("gradient").style.background="-moz-linear-gradient(top, "+color1+", "+color2+")";
    document.getElementById("gradient").style.background="-ms-linear-gradient("+color1+", "+color2+")";
    document.getElementById("gradient").style.background="-o-linear-gradient("+color1+", "+color2+")";
    document.getElementById("gradient").style.background="linear-gradient("+color1+", "+color2+")";
document.getElementById("gradient").style.filter="progid:DXImageTransform.Microsoft.Alpha(startColorstr='"+color1+"', endColorstr='"+color2+"')";

    }
    </script>

    <input type="text" id="color1" onkeyup="myFunction()" value="#E9EDF6"></input>
    <input type="text" id="color2" onkeyup="myFunction()" value="#AABBDD"></input>

    <div id="gradient" style="height:500px">
        I have gradient
    </div>

The function works fine in Firefox and IE10, but not in older IE versions.
I am guessing it’s because the last background call overwrites the others which are meant for older IE versions.

So how would you go about this?
Should I create a function which first checks the browser used before calling the color change function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:19:10+00:00Added an answer on June 17, 2026 at 2:19 pm

    You may want to take a look at the amazing Ultimate CSS Gradient Generator.

    As you can see, it generate more code than what you do, with comments at the end of each line indicating which browsers are affected by that line:

    background: #1e5799; /* Old browsers */
    background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
    background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
    

    Specifically, the last line is what you need, used for IE6-IE9.

    You may want to include first line too, for older browsers (IE5.5…) that do not handle Gradients.


    EDIT

    Add the filter part in javascript too, after the other lines:

    document.getElementById("gradient").style.filter = 
             "progid:DXImageTransform.Microsoft.Alpha(startColorstr='"+
                     color1+"', endColorstr='"+color2+"')"
    

    And, according to this answer, be sure to set overflow: auto or to set an height to your object.


    EDIT #2

    You are right, it will break with the other properties (with in CSS does not affect it).

    Then check if it’s IE, and use this JS:

    document.getElementById("gradient").filters.item("DXImageTransform.Microsoft.gradient").startColorstr = color1;
    document.getElementById("gradient").filters.item("DXImageTransform.Microsoft.gradient").endColorstr = color2;    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create super script for desired text selected by user. I found
So basically I want to create a batch script that can run any notepad
I want to create a script that will set the file associations for mostly
I want to create script to edit photos in galery. I have there textbox
I'm a student from indonesia and I want to create an script that deletes
JavaScript. I want to create simple script, that will be resize loaded image using
I want to create a powershell script that creates a shortcut in the windows
I want to create an SQL script that creates a database. Right now, I
I want to create a deployment script, somehow emulate Oracle deployment scripts, where with
I want to create an application in Apps Script that would fetch my Latitude

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.