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

The Archive Base Latest Questions

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

I am implementing the code that I get from internet and I put a

  • 0

I am implementing the code that I get from internet and I put a select on it.
The element is messed up when I do this step on Chrome browser;

  1. I move the element and drag it.
  2. I choose select and then the element is moving to left top page.

Please help, just simply copy and paste this code to your editor and run it;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<script type="text/javascript">
    //object of the element to be moved
    _item = null;

    //stores x & y co-ordinates of the mouse pointer
    mouse_x = 0;
    mouse_y = 0;

    // stores top,left values (edge) of the element
    ele_x = 0;
    ele_y = 0;

    //bind the functions
    function move_init()
    {
        document.onmousemove = _move;
        document.onmouseup = _stop;
    }

    //destroy the object when we are done
    function _stop()
    {
        _item = null;
    }

    //main functions which is responsible for moving the element (div in our example)
    function _move(e)
    {
        mouse_x = document.all ? window.event.clientX : e.pageX;
        mouse_y = document.all ? window.event.clientY : e.pageY;
if(_item != null)
{ 
_item.style.left = (mouse_x - ele_x) + "px";
_item.style.top = (mouse_y - ele_y) + "px";
}
}

//will be called when use starts dragging an element
function _move_item(ele)
{
//store the object of the element which needs to be moved
_item = ele;
ele_x = mouse_x - _item.offsetLeft;
ele_y = mouse_y - _item.offsetTop;

}
</script>
</head>
<body onload="move_init();">
    <div id="ele" onMouseDown="_move_item(this);" style="width:100px; height:100px; background-color: gray; position:fixed;">
    <select onmousedown="">
        <option>Oh</option>
        <option>Yes</option>
        <option>No</option>
        </select>
</div>
</body>
</html>

Would you please help me to fix the code…

  • 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-08T01:08:41+00:00Added an answer on June 8, 2026 at 1:08 am
     var draggable = function(element) {
        element.addEventListener('mousedown', function(e) {
            e.stopPropagation();
    
            // if the current target is different (in the case of a child node), don't drag.
            // you can customize this to specify types of children which prevent dragging
            if (e.target != element)
                return;
    
            var offsetX = e.pageX - element.offsetLeft;
            var offsetY = e.pageY - element.offsetTop;
    
            function move(e) {
                 element.style.left = (e.pageX - offsetX) + 'px';
                 element.style.top = (e.pageY - offsetY) + 'px';
            }
            function stop(e) {
                // remove the event listeners on the document when not dragging 
                document.removeEventListener('mousemove', move);
                document.removeEventListener('mouseup', stop)
            }
    
            document.addEventListener('mousemove', move)
            document.addEventListener('mouseup', stop)
    
        })  
    
    
    }
    
    function init() {
      var ele = document.getElementById('ele');
      draggable(ele)
    }
    

    This may not work in some IE versions, but you should be able to add the necessary fixes for that. Here’s the fiddle http://jsfiddle.net/seKbz/2/

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

Sidebar

Related Questions

When implementing the Strategy Pattern, where does one put the code that determines which
I'm revisiting and re-implementing the code that caused me to ask this question about
Am having a number of problems implementing the code from the Washington Post site
implementing publishActivity in PHP using the REST API using this code: $activity = array(
I've successfully implemented a bit of code that strips all HTML from a pasted
I have a UIView subclass that draws a simple rectangle with this code: -
I have a some simple Java code that looks similar to this in its
I'm implementing on some C++ code that I would like to make as portable
I'm implementing some code generators, i would like to know if there's any way
I'm implementing a code in matlab to solve quadratic equations, using the resolvent formula:

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.