472,972 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 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 6193
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.