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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:06:00+00:00 2026-06-04T17:06:00+00:00

I have 4 textboxes that make up an input for a text-shadow property, and

  • 0

I have 4 textboxes that make up an input for a text-shadow property, and are contained within a DIV like so:

<div id="shadow">
    <input type="number" min="-5" max="5" step="1" value="0" id="hshad" />
    <input type="number" min="-5" max="5" step="1" value="0" id="vshad" />
    <input type="number" min="0" max="20" step="1" value="0" id="bshad" />
    <input type="text" value="#000000" id="cshad" />
</div>

Right now, I manually combine the four inputs to get a desired css value. Something like this:

$('#elem').css('text-shadow', $('#hshad').val() + "px " + $('#vshad').val() + "px " + $('#bshad').val() + "px " + $('#cshad').val());

Is there a way I could ‘map’ these values to the value of #shadow as both a getter and a setter?

For example $('#shadow').val() would give me

"0px 1px 5px #FFFFFF"

And I could set the values of the four inputs by doing:

$('#shadow').val("0px 1px 5px #FFFFFF")

This is pretty much for the purpose (because I know you’ll ask) of being able to loop through CSS rules and set form field values when editing a record that has pre-exiting rules. This all goes to a wicked WYSIWYG I’m making.

EDIT

Ok, so it’s important for the sake of this question to pass back from val(). I’m looping through ~20-30 CSS rules, and don’t want to have to get stumped on a single rule. I could just go back after the loop and break apart the value, but I was hoping to extend val and keep my code in a nice, tidy loop.

Example

My CSS to loop (as JSON object)”

{
    "top": "48px",
    "left": "59px",
    "width": "100px",
    "height": "100px",
    "font-family": "Oxygen",
    "font-size": "1em",
    "font-weight": "normal",
    "color": "rgb(51, 51, 51)",
    "text-shadow": "rgb(0, 0, 0) 1px 0px 0px",
    "background-color": "rgba(0, 0, 0, 0)",
    "border-radius": "0px",
    "-moz-border-radius": "0px",
    "box-shadow": "none",
    "-moz-box-shadow": "none",
    "padding": "0px"
}

I give each form field a data-prop attribute for its associated CSS property like so:

<input type="text" data-prop="font-family" />

Then I would loop the rules like so

$.each(cssRules, function(name, value) {
  $('[data-prop=' + name + ']').val(value);
})

Nice, neat, and cozy.

  • 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-04T17:06:03+00:00Added an answer on June 4, 2026 at 5:06 pm

    http://jsfiddle.net/XCCgv/4/

    $.valHooks.div = {
    
        get: function( elem ) {
            if( elem.id !== "shadow" ) return;
    
            return $.map( $("input", elem ), function (element,index) {
                    return index === 3 ? element.value : element.value + "px"
            }).join(" ");
    
        },
    
        set: function( elem, value ) {
            if( elem.id !== "shadow" ) return;
    
            var inputs = $( "input", elem );
    
            $.each( value.split(" "), function( index, value ) {
                var val = parseFloat(value);
                inputs[index].value = isNaN(val) ? value : val;
            });
    
            return true;
        }
    
    };
    

    Edit: I saw your edit but I think you get the idea from here… you can check $(elem).data() in the valHook and call a different function depending on that. Here I am just checking for .id === "shadow"

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

Sidebar

Related Questions

I have a rails form that has a datetime input. I'd like to make
I have a number of textboxes that will be displayed with their existing values.
I have a textbox that must have a MIN number of characters as well
I have a jqueryui datepicker associated with a input text. When i make the
Say I have a textbox in HTML using the following code: <input type=text name=text
i have 2 textboxes that i am filling with StartDate, and Endate. i want
I have a few textboxes that are not required. If the user enters nothing
I have C# MVC web app that has some textboxes that in IE9 you
So basically, I have a bunch of TextBoxes that the user gets to fill
Lets just say that I have three textboxes: TextBox1, TextBox2, TextBox3. Normally if I

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.