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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:33:37+00:00 2026-06-03T02:33:37+00:00

Ok I have created a JavaScript page where the user can add text, they

  • 0

Ok I have created a JavaScript page where the user can add text, they can set the colour, bold italics, as well as size and font. Size and drop options are selected through drop down boxes.

enter image description here

It looks a bit messy atm, as I am not worried about the looks, just the functionality.

When they add an element which appears in the widget, they can drag the element into position onto an image I have created which is displayed on the screen. Whenever the user is happy with the position of the text, they click save which generates the coordinates and updates the table X and Y coordinates field, At this point, a new row is generated and they can repeat the process of adding a new element. Whenever they are happy, they click save and it will send to a database to store it to be retrieved later.

My problem is everytime I add a new text field, it pushes the element down by a certain amount.

I rectified this by adding a decrementing variable which takes the elementCount (which autoincrements every time they add a new label element) and multiply it by a set amount to decrement by

decr -= (elementCount* 16);

This works fine for the medium text size, however when you start adding different text sizes and font combinations, it will change how much the element gets pushed down so it gets worse and worse every other element you add.

The new element is added like this

        elementCount++;

      var Text = textArray[textArray.length-1];
       var Font = fontArray[fontArray.length-1];
       var Color = colorArray[colorArray.length-1];
        var Bold = boldArray[boldArray.length-1];
        var Size = sizeArray[sizeArray.length-1];
        var Italics = italicsArray[italicsArray.length-1];
        var X = xCordArray[xCordArray.length-1];
        var Y = yCordArray[yCordArray.length-1];

         var newdiv = document.createElement('div');
     newdiv.innerHTML = "<span><font color='" + Color + "' size = '" + Size + "' face='" + Font + "'><label class = 'drag2' id = 'text" + firstCount + "'> " + Text + "</label></font></span>";
    document.getElementById(divName).appendChild(newdiv);


        var decr= 32;
        decr-= (elementCount* 16);
        Y = parseInt(Y) + test;
        X = parseInt(X) + 24;


           document.getElementById("text" + elementCount).style.left = X + "px";
           document.getElementById("text" + elementCount).style.top = Y + "px";

The drag and drop JavaScript code was based on this tutorial

http://luke.breuer.com/tutorial/javascript-drag-and-drop-tutorial.aspx

Is there any way to make it so when you dynamically add a new element , it doesn’t automatically push it down the screen by a bit each new element you add. I have tried soo many different options to fix this over the past few days and have had no luck.

Thanks in advance for any help

Edit CSS for the text element

   .text1{
position: relative;
left: 0px;
top: 0px;

}
  • 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-03T02:33:39+00:00Added an answer on June 3, 2026 at 2:33 am

    I changed to absolute positioning and placed it inside a relative positioned container and works perfectly now!!

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

Sidebar

Related Questions

Can JavaScript classes/objects have constructors? How are they created?
A lot of JavaScript libraries have user interface widgets. Usually they are created after
I have created a signup page on my site, but the javascript validation function
I have created two JavaScript files. One file is "validators.js" and the other is
I am currently trying to pass an array that I have created in Javascript
I have created tab style interface using css and javascript with only two tabs
I'm creating a javascript battleships game. The game works fine. I have created the
I have problem with dynamically created image (JavaScript). I want to change the innerHTML
I have an array I've created in JavaScript. The end result comes out to
I have a few divs created dynamically in Javascript.I was wondering if it is

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.