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

  • Home
  • SEARCH
  • 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 8702607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:41:41+00:00 2026-06-13T02:41:41+00:00

I have two input fields, where people can write numbers. And what I need

  • 0

I have two input fields, where people can write numbers. And what I need is when a person finished writing in this input field some constant words or symbols are left there near his number.

I think that you didn’t get anything from what I wrote above so I will try to explain with this example: example

In the upper there are two inputs you see what person printed himself. And two inputs in the bottom are what he gets when he puts his cursor out of the input where he was printing.
(I don’t need all four inputs, just two…upper two just show the first step and bottom two show the final step)

I think it can be done by javascript… but I couldn’t do it by myself and I couldn’t find anything in web…

  • 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-13T02:41:42+00:00Added an answer on June 13, 2026 at 2:41 am

    I’ve used the following before, the reason I chose using an image over anything else was because text added to an input dynamically can cause confusion, as well as getting in the way when users wish to edit. Using an image meant it could be constantly there and wouldn’t get in the way of the user typing:

    It’s only written in jQuery because it was lying around, this could easily be rewritten in pure js – and it could easily be optimised.

    http://jsfiddle.net/pafMg/

    css:

    input { 
      border: 1px solid black;
      background: #fff;
      padding: 2px;
    }
    

    markup:

    <input class="right-aligned" type="text" />
    <input class="left-aligned" type="text" />
    

    code:

    In the following code the padding-left and padding-right has to take into account the width of the image you use.

    $(function(){
      /* For left aligned additions */
      $('input.left-aligned')
          .css({
              'padding-left': '20px',
              'background-image': 'url(/favicon.png)',
              'background-position' : '2px center',
              'background-repeat': 'no-repeat'
          });
    });
    

    The left aligned version is really simple, the right aligned gets a little bit more complex however:

    $(function(){
      /* For right aligned additions */
      $('input.right-aligned')
          .bind('keypress keyup', function(e){
              var input = $(this), measure, text = input.val(), x, w, y;
              /// You can calculate text width, but it's not easily cross-browser
              /// easier method, inject the text to a span and measure that instead
              if ( !input.data('measure') ){
                  /// only build our measuring span the first time
                  measure = $('<span />')
                      .hide() // hide it
                      .appendTo('body')
                      /// try and match our span to our input font
                      /// this could be improved
                      .css({
                          'font-weight':input.css('font-weight'),
                          'font-family':input.css('font-family'),
                          'font-size':input.css('font-size')
                      });
                  /// store the measure element for later
                  input.data('measure', measure );
              }
              /// handle if the user types white space
              text = text
                  .replace(/\s/g,'&nbsp;')
                  .replace(/</g,'&gt;');
              measure = input.data('measure');
              measure.html(text);
              w = measure.width();
              y = input.width();
              /// calculate the image position (minus padding)
              x = w + parseInt(input.css('padding-left')) + 2;
              /// take into account the scroll ability of an input
              x -= ( w > y ? w - y : 0 );
              /// reposition our image background on the input
              input
                  .css({
                      'padding-right': '20px',
                      'background-image': 'url(/favicon.png)',
                      'background-position' : x + 'px center',
                      'background-repeat': 'no-repeat'
                  });
          }).trigger('keyup');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope I can explain this right I have two input fields that require
I have two input fields, Id and Desc. I need a javascript which enters
I have this code here http://jsfiddle.net/RzBeM/65/ you will see two input fields called quantity.
I have two logical groups of input fields I need to validate separately using
I have two input fields that need to hide when first visit. There will
I have two input fields, and without changing their names (i.e., I have to
I have got two input fields which i would like to make editable with
I have a usual login form consisting of two input fields, one for login,
I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input
I have an HTML5 Canvas on my page along with two text input fields.

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.