473,799 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

please... some info would be very appreciated.

Hello all,

First let me tell you that I have searched this group and the internet
and have not been able to find the answer to my problem. It is probably
because I don't know what to look for. I did though find my question
asked in 1997 by a guy in this group but it seems that noone answered
his(my) question. As a very last resort I ask my question now.

I have a function to handle many divs. How do I pass that function the
'object' of the div, so that I may change its style.

---
<div id="layer1" style="position :absolute;top:0 ;left:0;"></div>
<script language="javas cript">
function move(divname){
divname.style.t op = 100;
}

move(window.doc ument.all.layer 1);
</script>
---

If you could give me any help it would be very much appreciated!
Primus

Jul 23 '05 #1
11 1526
primus wrote:
Hello all,

First let me tell you that I have searched this group and the internet
and have not been able to find the answer to my problem. It is probably
because I don't know what to look for. I did though find my question
asked in 1997 by a guy in this group but it seems that noone answered
his(my) question. As a very last resort I ask my question now.

I have a function to handle many divs. How do I pass that function the
'object' of the div, so that I may change its style.

---
<div id="layer1" style="position :absolute;top:0 ;left:0;"></div>
<script language="javas cript">
function move(divname){
divname.style.t op = 100;
}

move(window.doc ument.all.layer 1);
</script>
---

If you could give me any help it would be very much appreciated!
Primus


one way is:

function move(divname){
document.getEle mentById(divnam e).style.top = 100;
}
move("layer1");

but that will only work with browsers that support getElementById

now check message news:US******** **********@text .news.blueyonde r.co.uk
Michael Winter added a nifty checker in there.

there, if I understand it correctly, you would add the "var getReferenceByI d..." code
into your move() function - changing move(divname) to move(id) or replacing the "id"
references to "divname", whichever is easier for you - and then add

if(getReference ById && getReferenceByI d.style) getReferenceByI d.style.top = 100+'px'.

I'm not sure where 'px' doesn't work, but there is a browser that doesn't work right
if you omit the 'px' addition.

Robi
Jul 23 '05 #2
ASM
primus wrote:
Hello all,
Hello alone,
As a very last resort I ask my question now.
I have a function to handle many divs. How do I pass that function the
'object' of the div, so that I may change its style.


<html>
<style type="text/css">
* { text-align: center }
</style>
<script type="text/javascript">
function move(divname,le ft,top){
if(document.get ElementById) {
var d = document.getEle mentById(divnam e).style;
if(top) d.top = top+'px';
if(left) d.left = left+'px';
}
}
</script>
<div id="layer1"
style="position :absolute;top:0 ;left:0;width:2 00px;border:1px solid red">
<h2>DIV 1 to move</h2>
<p><a href="javascrip t:move('layer1' ,100,50);">
move layer1 from window-top = 50, from window-left = 100
</a>
<p><a href="javascrip t:move('layer2' ,320,20);">
move layer2 to window-top = 50, and window-left = 320
</a>
</div>
<div id="layer2" style="position :absolute;top:0 ;
left:-300;width:200px ;border:1px solid red">
<h2>DIV 2 to move</h2>
</div>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #3
Thank you! Thank you! Thank you!

My headache is gone now! I didn't know it was that easy.

Again Thank You,
Primus

Jul 23 '05 #4
ASM
ASM wrote:
[snip]
[follow]

if you need a compatibility even with my NC4.5 or IE4
use that :

<script type="text/javascript">
function move(divname,le ft,top){
var d = (document.all)? document.all(di vname).style :
(document.getEl ementById)?
document.getEle mentById(divnam e).style :
(document.layer s)? document.layers[divname] :
'';
var p = document.layers ? '' : 'px';
if(top) d.top = top+p;
if(left) d.left = left+p;
}
</script>

Sorry, I didn't use :
getReferenceByI d
from Michael Winter

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #5

From the event obj, use literally 'this':

<div onclick="alert( this.innerHTML) "> <b> shows this html</b> upon
clicking</div>
Danny

On Wed, 13 Jul 2005 16:49:05 -0700, primus <pr************ *****@gmail.com >
wrote:

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #6
Danny wrote:

From the event obj, use literally 'this':

<div onclick="alert( this.innerHTML) "> <b> shows this html</b> upon
clicking</div>


And hope the UA supports innerHTML. Learn to code before posting here
please.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #7
ASM wrote:
<snip>
if you need a compatibility even with my NC4.5 or IE4
use that :

<script type="text/javascript">
function move(divname,le ft,top){
var d = (document.all)? document.all(di vname).style :
(document.getEl ementById)?
document.getEle mentById(divnam e).style :
(document.layer s)? document.layers[divname] :
'';
It cannot be a good plan to place the above inside the body of a
function that wants to make reference to a DOM element. Making such a
reference is such a common task that the same (or similar) code would
need to be repeated inside many function bodies as the size of the code
increases.

Instead it would make more sense to recognise that this is a task that
would be more usefully done in a dedicated external function, or two
(one for element reference retrieval and one for style object
normalisation.
var p = document.layers ? '' : 'px';
This is object inference. It is not necessarily true that a browser that
implements a document.layers collection does not require/understand 'px'
units appended to a string that is to be assigned to a top or left
property (it is even a bit dubious to be assigning a string).

A more direct test would examine the existing top or left property and
only add units where that property was a string. And where the property
is not a string then it woudl also be better not to be assigning a
string value. The latter can be achieved by taking advantage of the duel
nature of the + operator; E.G.:-

p = (typeof d.top == 'string')?'px': 0;

- so:-

d.top = top + p;

Assigns a string with 'px' appended if top was a string, and a number
with zero added (so unchanged) if it was not a string.

There is still an assumption in this approach but it is an assumption
based on a test that has a close relationship with the action taken as a
result, so it is an assumption that is less vulnerable to the influence
of the unknown browser.
if(top) d.top = top+p;
if(left) d.left = left+p;

<snip>

If the function is passed top or left values of zero the above tests
will cause it not to apply those values. Once positions have been set to
non-zero values it is completely reasonable to assign zero value to
those positions.

Richard.
Jul 23 '05 #8
On 14/07/2005 02:03, Robi wrote:
primus wrote:
[snip]
<script language="javas cript">
function move(divname){
divname.style.t op = 100;
}

move(window.d ocument.all.lay er1);
</script>


[snip]
now check message news:US******** **********@text .news.blueyonde r.co.uk
Michael Winter added a nifty checker in there.

there, if I understand it correctly, you would add the "var getReferenceByI d..." code
into your move() function - changing move(divname) to move(id) or replacing the "id"
references to "divname", whichever is easier for you - and then add

if(getReference ById && getReferenceByI d.style) getReferenceByI d.style.top = 100+'px'.


The code I posted results in the creation of one of three functions. The
first is a simple wrapper around the document.getEle mentById method. The
second uses the document.all collection to emulate gEBI by filtering the
results that the all collection might return. The final function simply
returns null, and will be used if the host supports neither gEBI nor the
all collection.

Part of the purpose of this code is to create a slightly more guaranteed
environment. That is, getReferenceByI d will always exist, so you can
rely on your ability to call it. All you need to do is check the return
value to make sure you have an object reference.

So, instead of:

var obj = document.getEle mentById('myEle ment');

if(obj) ...

you'd write:

var obj = getReferenceByI d('myElement');

if(obj) ...

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #9
ASM
Richard Cornford wrote:
ASM wrote:
<script type="text/javascript">
function move(divname,le ft,top){
var d = (document.all)? document.all(di vname).style :
(document.getEl ementById)?
document.getEle mentById(divnam e).style :
(document.layer s)? document.layers[divname] :
'';

It cannot be a good plan to place the above inside the body of a
function that wants to make reference to a DOM element. Making such a
reference is such a common task that the same (or similar) code would
need to be repeated inside many function bodies as the size of the code
increases.


Yes you're absolutly right and I agree with you.
(but in this answer the purpose was not to rebuild the world
nor to confuse querer (fr: questionneur) )
var p = document.layers ? '' : 'px';


p = (typeof d.top == 'string')?'px': 0;

- so:-

d.top = top + p;


Good ! thanks
If the function is passed top or left values of zero the above tests
will cause it not to apply those values. Once positions have been set to
non-zero values it is completely reasonable to assign zero value to
those positions.


not understood (I'll try and see)

I dit test on Mac my function in : NC4.5, FF 10, IE 5.2
and ... did work correctly :-)

thanks for *validate* corrections
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #10

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

Similar topics

3
2911
by: Baby Blue | last post by:
I have 2 codes below to grap data from another site. I use them to get the data from one News site. However, when I click on some link inside (such as : http://www.thuthao.info/news/chitiet.php?url=http://vnexpress.net/Vietnam/Kinh-doanh/2005/01/3B9DB0AC/ ), there are some errors, I try fix some, but hopeless. CAN ANY BODY HELP ME ??? MUCH APPRECIATED demo : news.thuthao.info real site : www.vnexpress.net Code of Index.php
0
1749
by: Richard Gabriel | last post by:
Hi everyone, Since we upgraded to MySQL 4.0.13 from 3.23, we have been getting table corruption often. It happens about twice per week (with about 500 queries per second average). I have even set up a cron to run mysqlcheck every hour to try to do some damage control. The biggest problem is that once the table is corrupted, it seems to be locked. Well, no clients can read from it. Once repaired, just one record is usually lost for...
3
1775
by: Nicolae Fieraru | last post by:
Hi All, I have a lot of problems with the web site www.ggsurf.com.au I host on www.gnxonline.com and I want to find out if it is my own problem or theirs. I try to use session cookies and it doesn't work fine. Eventually I created some test scripts, which can be found in here: www.ggsurf.com.au/info.asp There is a link to Set the Session("TransactionID") = 25 and the page
9
2416
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a single string separated by a user defined character. There is no error trapping (by design), USE AT YOUR OWN RISK.
1
1543
by: Jim | last post by:
I've posted this a couple of times, no luck so far. Any info would be greatly appreciated. The tooltips are very useful, but this oddity is very annoying, particularly because I'm visually handicapped and it's very visually distracting) when a tooltip ends up taking up the entire screen... Using Intellisense, when I type a function name and the opening parenthesis, I get a tooltip that identifies the return type and arguments of the...
3
4266
by: prabhupr | last post by:
Hi Folks Not sure if this is the right group, if not please re-direct me to the right one. Here is my question =============== When I compile my ASP.NET WEB project from VS 2005 (.NET Framework 2.0) IDE, it works fine, but if I use NANT (Build Automation) it gives me an error as follows:
0
1269
by: Joe | last post by:
i posted similar to vb forum but without success. Can anyone help here I have been wrestling with a problem for days. The solution is probably simple but i am not that experienced with html. I have a vb program which sends info to a web page and as that page fills up a button is 'pressed' and the page is submitted, cleared and reloaded again. To login to the site the code is as follows oIE.Document.Forms("Login").All("district").Value...
6
1363
by: chanko | last post by:
hi all! ok i'll try and keep this clean and simple i have a web app where users can log in and manage a mini site (ie galleries, files, news....) and i have a web app which is the site where all that info they can manage is displayed to the public
6
1741
by: shaunb | last post by:
Hi, just new to this forum, and i was wondering if anyone could help me. I've got a piece of work to do, i have done the majority of it, just the last, and the most important thing lol, that i am stuck with. there are 4 classes, Room, Bedroom (type of room), ConferenceRoom (type of room) and Date(in a header file). class Room{ private: int roomNumber; double rate;
1
1994
by: Larry Hale | last post by:
Since it seems I have a "unique" problem, I wonder if anyone could point me in the general/right direction for tracking down the issue and resolving it myself. See my prior post @ http://groups.google.com/group/comp.lang.python/browse_thread/thread/44775994a6b55161?hl=en# for more info. (Python 2.5.2 on Win XP 64 ==>Squid Proxy requiring Authentication ==>Internet not working.) I've looked the urllib2 source over, but am having...
0
10252
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...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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
9073
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
7565
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
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
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
2938
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.