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 8283633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:48:08+00:00 2026-06-08T10:48:08+00:00

How do you run jscolor after an ajax post that resets a forms elements

  • 0

How do you run jscolor after an ajax post that resets a forms elements back to their default value?

The ajax below successfully posts to the in page iframe and restores in page form values to default when you click the “Restore Default” button. The problem is that the inputs that have jscolor attached to them don’t change their background color back to their defaults.

The research I have done leads me to believe that I need to re-initiate jscolor with jscolor.init(); after the ajax post but I can’t get it to work. I also tried building a function outside of the ajax post (that resets form values then jscolor.init();) and binding it to the “Restore Default” button with onclick but that didn’t work.

How can I get jscolor to run again after the ajax post?

Javascript:

<script type="text/javascript">
$(document).ready(function() {
    $('#restore_form').click(function() {
        $.ajax({
            data: $('#build_form').serialize(),
            type: $('#build_form').attr('method'),
            url: $('#build_form').attr('action')+'?type=restore',
            success: function(response) {
                $('#preview').contents().find('html').html(response);
                $('#build_form')[0].reset();
                jscolor.init();
            }
        });
        return false;
    });
});
</script>

HTML:

<iframe id="preview" src="preview.php" width="100%" height="120"></iframe>

<form id="build_form" class="build_form" action="preview.php" method="post">
    <input type="text" name="background_color" value="#0CA0E2" class="color {adjust:false,hash:true}" />
    <input id="restore_form" name="restore" type="submit" value="Restore Default" class="button" />
    <input id="save_form" name="submit" type="submit" value="Save Changes" class="button" />
</form>
  • 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-08T10:48:09+00:00Added an answer on June 8, 2026 at 10:48 am

    Try to reset the color. Seeing your markup, I think that your default color is 0CA0E2. Am I corret? If so, you just need to (if you used the jscolor constructor and assign the new object to the myJsColorVar var):

    myJsColorVar.color.fromString("0CA0E2"); // instead of jscolor.init()
    

    In the docs, it is used:

    document.getElementById("myColorInput").color.fromString("0CA0E2");
    

    I think that the last example is better for you, since I saw that you didn’t create your jscolor in JS, but applied the “color class”.

    You will just need to configure an id for your color input:

    <form id="build_form" class="build_form" action="preview.php" method="post">
        <input id="myColorInput" type="text" name="background_color" value="#0CA0E2" class="color {adjust:false,hash:true}" />
        <input id="restore_form" name="restore" type="submit" value="Restore Default" class="button" />
        <input id="save_form" name="submit" type="submit" value="Save Changes" class="button" />
    </form>
    

    Take a look here: http://jscolor.com/try.php#setting-color

    Edit: I created a custom jscolor.

    <html>
        <head>
            <title>jscolor demo</title>
        </head>
        <body>
            <script type="text/javascript" src="jscolor.js"></script>
            <script type="text/javascript">
    
                function CustomJSColor( applyIn, defaultColor, opts ) {
    
                    this.jscolor = new jscolor.color( document.getElementById( applyIn ), opts );
                    this.defaultColor = defaultColor;
                    this.jscolor.fromString( this.defaultColor );
    
                    this.reset = function() {
                        this.jscolor.fromString( this.defaultColor );
                    };
    
                }
    
            </script>
        <body>
            <input id="myField">
            <script>
    
                // the input with id "myField" will be the color picker
                // 0099cc is the default color
                // {} is the other options
                var myPicker = new CustomJSColor( "myField", "0099cc", {} );
    
                // to reset the color you just need to call reset
                myPicker.reset();
    
            </script>
        </body>
    </html>
    

    I tried to inherit from jscolor.color but it seems that is not a constructor, so I created that class, that have one jscolor inside it. To reset the color of a component, you just need to call the reset method. Take care, because just using the “color” class will not create a CustomJSColor. You need to create it programmatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run this query: SHOW INDEX FROM `tbl_clients` I get back these: Table, Non_unique,
I run LoginForm using the code below: [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);
We run an AI programming competition in which contestants will code an AI that
I run a SaaS that allows free trials. Basically if you register you get
I run into following code in my project: html: <input type=button id=addmore value=Add more
I run a fairly active student blog that uses this event calendar plugin to
I run a website and there is an area to send messages with AJAX.
I run the following code and I get back a pretty involved object back.
I run multiple webpages that I have programming in .net. I am looking at
I run a service when the device boots and that service just loads an

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.