473,796 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrive top value for div

I have a function which is called in during an onclick. The function needs
to determine the current position of a div, and act according to whether it
is currently a positive, negative or zero value.

I am able to move the div by doing the following:
document.getEle mentById('locat or').style.top += 10;

If I try to retrieve this value with this:
var t = document.getEle mentById('locat or').style.top;
alert(t);
But, it never shows any value, so I cannot determine its current value.

Any help is appreciated.


Jul 23 '05 #1
1 7972
news.west.cox.n et wrote:
I have a function which is called in during an onclick. The function needs
to determine the current position of a div, and act according to whether it
is currently a positive, negative or zero value.

I am able to move the div by doing the following:
document.getEle mentById('locat or').style.top += 10;
Not in any browser I tested.

If I try to retrieve this value with this:
var t = document.getEle mentById('locat or').style.top;
alert(t);
But, it never shows any value, so I cannot determine its current value.

Any help is appreciated.


If you haven't given the top property a value, it won't have one - so
it *is* showing you the current value. :-)

When setting top, it must have a unit (px, em, etc.). When changing
it, you have to allow for the units, so remove & save the units, add
the value, then replace the units.

Note that top may be set to 'auto' or percent. If you want px, then
set 'top' to some value - 0px if required.

Some play code below, lightly commented and tested in IE and Firefox.
<input type="button" style="position : relative; top: 0px;" onclick="
var x = this.style.top;
var unit = x.replace(/\d/g,''); // Get unit
x = x.replace(unit, ''); // Get value
if ('px' == unit) {
this.style.top = +x + 10 + unit; // Increment & replace unit
} else {
// If unit was anything other than px
this.style.top = '10px';
}
" value="Push me down...">

--
Rob
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3056
by: Learner | last post by:
Hi there, I have a storec proc that schedules a Sql job and finally it returns 0 then it was successfull and if it returns 1 then its unsuccessful. Now when i run the stored proc in the query analyzer its returning SQLServerAgent is not currently running so it cannot be notified of this action. Stored Procedure: aisinspect.dbo.SP_ChangeInspectionDateNew
1
2603
by: mandakini | last post by:
Hello freinds I am working on this url http://72.36.156.243/compbuild.php Here I am using ifram and displaying dynamic value I don't know how to use iframe as array how to assign array and retrive value from array. I am very poore in javascript please help me. coding is like this
2
1436
by: RAHULPRAJAPATI | last post by:
I Have One Module , In Which I Have To Find Perticular Person's Data . It Is Easily To Get But Here Large No. Of Data I Have, I Know That It Is Possible But It Is Very Much Time Conusuming, So, Any Other Way To Retrive Value By Minimum Time Consuming Reply As Soon As Possible Thanks, Rahul Rahul_nadiad@yahoo.com
0
1277
by: avishekb | last post by:
can anyone suggest me how to retrive data from a xml file using c/c++. for example: <schema> <applt to>portno</applyto> <type>int</type> <value>8080</value> </schema> i want to retrive the value 8080 from the file and assign it to portno,so that when i am using portno in my program it will be replaced by 8080.
1
1765
by: deepaks85 | last post by:
Dear Friends, I have create a form in which user can update his/her records. The data can retrieved from the code which i have put in dropdown menu. Now I want to display all the records as per the dropdown menu changed. I have retrieved proposalcode from the table in a dropdown menu and from that dropdown menu I am selecting records from the same table. I have tried it but I don't know why I am getting error. I am getting the...
1
1677
idsanjeev
by: idsanjeev | last post by:
hello i wants to retrive data in textarea like input text but in textarea value is not work so what should be use to retrive textarea value after any error <input type="text" name="name" value="<%=name%>"> [/code>
1
2200
by: bhargavi514 | last post by:
friends i need the code to retrieve value from database and display value in text area using php
1
1355
by: v2naveen | last post by:
Hi, I have table called CUSTOMER with the following fields and values Interval_date rec_value ------------- ---------- 10/1/2007 5:30:00 12.0 10/1/2007 6:00:00 17.0 10/1/2007 7:00:00 15.0 .
1
1888
by: abirami elango | last post by:
Hi, i have created a web application in vb.net. i have assigned a value to the textbox during page UNLOAD event as below.. ......... Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload txtPopConfirm.Text = intCountAnswer1 End Sub
1
1610
satiss7pwr
by: satiss7pwr | last post by:
i am creating dynamic text box and dropdownlist on one DropDownList7_SelectedIndexChanged event like this code public partial class AddMethod : System.Web.UI.Page { DropDownList drp=null ; TextBox txt=null ; int z;// it store store DropDownList7.SelectedValue . .
0
9685
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10244
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.