Results 1 to 6 of 6

Thread: How do i do this? [JavaScript] Help!

  1. #1
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do i do this? [JavaScript] Help!



    Please help me on this!

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What do you mean "change location" ?? Change it's position on the screen(like animating) or do you want it's target to change?

  3. #3
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi View Post
    What do you mean "change location" ?? Change it's position on the screen(like animating) or do you want it's target to change?
    Change position either x/y coordinate or pixel position

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh, it's extremely easy. Just change the element's left and top properties. If you dunno how to see this example:

    The js:
    Code:
    function move(){
    some_element = document.getElementById("some_id");
    some_element.style.left = "100px"; // moves the element some_element to 100px from the left
    some_element.style.top = "100px"; // moves the element some_element to 100px from the top
    }
    Code:
    <input type="button" onclick="move()" id="some_id">

  5. #5
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi View Post
    Oh, it's extremely easy. Just change the element's left and top properties. If you dunno how to see this example:

    The js:
    Code:
    function move(){
    some_element = document.getElementById("some_id");
    some_element.style.left = "100px"; // moves the element some_element to 100px from the left
    some_element.style.top = "100px"; // moves the element some_element to 100px from the top
    }
    Code:
    <input type="button" onclick="move()" id="some_id">
    Thx but Im a total newbie on this how could the final result look like^ I mean what should I write in the "some_element"? (its the button i want to be some_element?) how?!?

  6. #6
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how could the final result look like^ I mean what should I write in the "some_element"? (its the button i want to be some_element?) how?!?
    Watch and learn.

    Just paste it like this:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function move(){
    var some_element = document.getElementById("some_id");
    some_element.style.left = "100px"; // moves the element some_element to 100px from the left
    some_element.style.top = "100px"; // moves the element some_element to 100px from the top
    }
    </script>
    </head>
    <body>
    <input type="button" onclick="move()" id="some_id" style="position: absolute;">
    </body>
    </html>
    Again, this isn't what you wanted but just an example. It's your school project not mine.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •