473,388 Members | 848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Need help with form!

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:
Expand|Select|Wrap|Line Numbers
  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. }
  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:
Expand|Select|Wrap|Line Numbers
  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.
Mar 1 '09 #1
2 1127
8,658 Expert Mod 8TB
firstly, you certainly mean JavaScript (JavaScript != Java)

secondly, your Javascript code has an error (there is one curly bracket left over and a return statement out of a function).

well, it could be something with the time, the script is called, but I have too less info to say for sure.
Mar 1 '09 #2
16,027 Expert Mod 8TB
Yes, lines 14-19 should be within its own function which you could call, say, onclick of a button.

PS. please use [code] tags properly. See How to Ask a Question. Thanks!
Mar 4 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Crystal | last post by:
Ok, I know this sounds weird, but it's really bugging me. I have a few list boxes on my form (basic pick a month, year, state stuff) and you can only choose one value. I need to be able to run a...
by: Rodney King | last post by:
Hi, I have developed an ASP page which dynamically displays a list of checkbox options based on a SQL statement. Here is my code: <div style="OVERFLOW:auto; Height: 150px"> <table> <% dim...
by: cmc_dermo | last post by:
I have a form that has a select list. A user chooses a value and the page refreshes showing the selected value in the dropdown box. So I want to use Javascript to get the selected query from...
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms...
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.