473,386 Members | 1,830 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,386 software developers and data experts.

HELP: I need to make the div show up next to a button

Hi Guys,

I am having problem finding the position of a button that I can set the
div position next to the button.

Can you please help? Thanks in advance.

Jul 23 '05 #1
9 6209
I am using firefox thank you.

Jul 23 '05 #2
gl**@tollnz.co.nz wrote:
I am using firefox thank you.


You're welcome I'm sure. Ever hear of CSS?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/str*ict.dtd">
<html>
<head>
<style id="ss" type="text/css">

div#container {
position: relative;
width: 120px;
height: 200px;
margin: 160px auto;
}
button {
position: absolute;
top: 88px;
width: 60px;
height: 24px;
font: 12px tahoma;
}
div#div {
visibility: hidden;
position: absolute;
left: 80px;
top: 0;
width: 40px;
height: 200px;
border: 1px #000 solid;
background: coral;
}

</style>
<script type="text/javascript">

function x()
{
document.getElementById('div').style.visibility = 'visible';
}

</script>
</head>
<body>
<div id="container">
<button onclick="x()"> button </button>
<div id="div"></div>
</div>
</body>
</html>

Jul 23 '05 #3
gl**@tollnz.co.nz wrote:
Hi Guys,

I am having problem finding the position of a button that I can set the
div position next to the button.


Not to nit-pick, but what do you mean by 'position'?

Do you want to place the div using HTML/DOM rendering or absolute
co-ordinates (like a tool-tip)?

For HTML/DOM rendering, you can create a div and append it to anther
element similarly to if you'd coded it in the original HTML - or you
could code it in the HTML and have it hidden, then use script to
reveal it when a button is clicked.

If you are looking for a tool-tip kind of thing, you may be after the
coordinates of a mouse click.

Alternatively, you can get the location of the top left corner of the
button reasonably easily, but lower right is more difficult.

Here's finding the location of a mouse click (Firefox & IE):

<script type="text/javascript">
function sayPos(e){
e = e || window.event;
alert('X: ' + e.clientX + '\nY: ' + e.clientY);
}
</script>
<div id="divA" style="position:relative; height:100px;
border:1px solid red;"
onclick="sayPos(event);"></div>

Test thoroughly as the support for this stuff varies greatly across
different browsers.

More info? Tooltips:

<URL:http://www.walterzorn.com/tooltip/tooltip_e.htm>
Finding the coordinates of an element on a page (and lots of other
useful stuff about CSS/JavaScript/DOM/browser compatibility):

<URL:http://www.quirksmode.org/js/findpos.html>
--
Rob
Jul 23 '05 #4
umm...

I have a table and several buttons in rows like this
button1
button2
button3

and I have only 1 div,

when I click on button2, the javascript will set the div appear beside
the button.

Thanks

Jul 23 '05 #5
gl**@tollnz.co.nz wrote:
I have a table and several buttons in rows like this
button1
button2
button3
and I have only 1 div,
when I click on button2, the javascript will set the div appear beside
the button.
Thanks


This works in my IE 6, Netscape 7.2, Firefox 1.0.1. Code to detect top
of button found here:

http://www.quirksmode.org/js/findpos.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body{
width: 100%;
height: 100%;
}
#btnDiv{
display: none;
border: 2px solid red;
position: absolute;
padding: 0 5px 0 5px;
left: 100px;
}
input{
margin: 2px;
padding: 2px;
}
</style>
<script language="JavaScript" type="text/javascript">
function processbtnclk(objBtn){
objDiv=document.getElementById('btnDiv');
objDiv.style.top=findPosY(objBtn)+'px';
objDiv.style.display='block';
objDiv.style.visibility='visible';
}
function findPosY(obj){
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
} else if (obj.y){
curtop += obj.y;
}
return curtop;
}
</script>
</head>
<body>
<br>
<input type="button" onclick="processbtnclk(this)" value="button 1"><br>
<input type="button" onclick="processbtnclk(this)" value="button 2"><br>
<input type="button" onclick="processbtnclk(this)" value="button 3">
<div id='btnDiv'>This is the Div that moves next to the clicked button</div>
</body>
</html>
Jul 23 '05 #6
hi mscir

I tried using offsetLeft,Top, Parent
Some how I couldn't get the the div display correctly next to the first
button if I click the button more than once, the div just moved to the
right each time. Also I was visibility:visible instead of block, will
that make the difference?

Jul 23 '05 #7
gl**@tollnz.co.nz wrote:
umm...

I have a table and several buttons in rows like this
button1
button2
button3

and I have only 1 div,

when I click on button2, the javascript will set the div appear beside
the button.

Thanks

<style type="text/css">
..blah {border: 1px solid blue; width: 20em; height: 2em;
background-color: #eee;}
</style>
<script type="text/javascript">
function addDiv(x){
var id = 'c-' + x.id.split('-')[1];
var oDiv = document.createElement('DIV');
oDiv.className = 'blah';
document.createElement('DIV').appendChild(oDiv);
}
</script>
<table>
<tr>
<td>
<input type="button" value="button 1" id="b-1" onclick="
addDiv(this);">
</td><td id="c-1"></td>
</tr><tr>
<td>
<input type="button" value="button 2" id="b-2" onclick="
addDiv(this);">
</td><td id="c-2"></td>
</tr><tr>
<td>
<input type="button" value="button 3" id="b-3" onclick="
addDiv(this);">
</td><td id="c-3"></td>
</tr>
</table>
--
Rob
Jul 23 '05 #8
RobG wrote:

Ooops, cut 'n paste aint what it used to be...
function addDiv(x){
var id = 'c-' + x.id.split('-')[1];
var oDiv = document.createElement('DIV');
oDiv.className = 'blah';
document.createElement('DIV').appendChild(oDiv);
function addDiv(x){
var id = 'c-' + x.id.split('-')[1];
var oDiv = document.createElement('DIV');
oDiv.className = 'blah';
document.getElementById(id).appendChild(oDiv);
}
</script>
<table>

[...]

--
Rob
Jul 23 '05 #9
thanks rob.

Jul 23 '05 #10

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

Similar topics

2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
5
by: TrvlOrm | last post by:
HI There, I have been struggling with JavaScript code for days now, and this is my last resort! Please help... I am trying to create a JavaScript slide show with links for Next Slide,...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
5
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function...
2
by: Doug Slocum | last post by:
Hi, I'm using ASP.NET. I need help adding new buttons to my web page at run time on the server side prior to sending to the client. As the web form is loading, I won't know in advance how many...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: ebernedo | last post by:
Hey guys, I have two main questions First off (pictures are kind of blurry) I have this table http://i197.photobucket.com/albums/aa109/ebernedo/DiscTable.jpg And thats my database I use my...
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.