Web Hosting, Design, & Coding forum

General discussion

Help!

by xilovemusic123x / March 1, 2009 3:08 AM PST

Hi, I have a question about Java. I'm really new to Java so this is not something I'm familiar with..
My question is, how do I get the values of pos.offsetTop and pos.offsetLeft to show up in my input box??

Here is the java code:

1. function getPosition(element) {
2. var left = 0;
3. var top = 0;
4. if(element.offsetParent) {
5. while(element) {
6. left += element.offsetLeft;
7. top += element.offsetTop;
8. element = element.offsetParent;
9. }
10. }
11. return {offsetLeft: left, offsetTop: top};
12. }
13.
14. var element = document.getElementById('elem');
15. var pos = getPosition(element);
16. document.Show.X.value = pos.offsetTop;
17. document.Show.Y.value = pos.offsetLeft;
18. return true
19. }

Here's the HTML:

1. <div id="elem">My Element</div>
2. <form name="Show">
3. <input type="text" name="X" value="0" size="4"> X<br>
4. <input type="text" name="Y" value="0" size="4"> Y<br>
5. </form>

Can someone please help me fix my code.. I can't seem to get the values from the java into the form.

Discussion is locked
You are posting a reply to: Help!
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Help!
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Popular Forums
icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

CNET FORUMS TOP DISCUSSION

Help, my PC with Windows 10 won't shut down properly

Since upgrading to Windows 10 my computer won't shut down properly. I use the menu button shutdown and the screen goes blank, but the system does not fully shut down. The only way to get it to shut down is to hold the physical power button down till it shuts down. Any suggestions?