Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I need to show drop down dynamically after getting the position of click .

It mean i need to first find X and y coordinates of click event than show drop down(below that).


Like that
var select = document.createElement("select");

//Create a option element dynamically
var option = document.createElement("option");

..

Explain again :
On button click :i have 2 or three button i need to show menu option after click dynamically .so i thing first i have to calculate the x and y coordinate of click event.

i am doing like this .

i do like that ...
create region
<div id= 'menuOption'></div>


<li class="dropdown-toggle menu click_h" data-toggle="dropdown" href="javascript:void(0)" id="config" onClick='test()'>Configuration

</li>

function test(e){
var evt = e ? e:window.event;
var clickX=0, clickY=0;

if ((evt.clientX || evt.clientY) &&
document.body &&
document.body.scrollLeft!=null) {
clickX = evt.clientX + document.body.scrollLeft;
clickY = evt.clientY + document.body.scrollTop;
}
if ((evt.clientX || evt.clientY) &&
document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.scrollLeft!=null) {
clickX = evt.clientX + document.documentElement.scrollLeft;
clickY = evt.clientY + document.documentElement.scrollTop;
}
if (evt.pageX || evt.pageY) {
clickX = evt.pageX;
clickY = evt.pageY;
}

alert (evt.type.toUpperCase() + ' mouse event:'
+'\n pageX = ' + clickX
+'\n pageY = ' + clickY
+'\n clientX = ' + evt.clientX
+'\n clientY = ' + evt.clientY
+'\n screenX = ' + evt.screenX
+'\n screenY = ' + evt.screenY
)
return false;


}

i want to show drop down when i click configuration below this . i am getting the coordinates


Thanks
Posted
Updated 17-May-13 0:56am
v2

You can easily calculate the X-Coordinate & Y-Coordinate using below code using jquery:
JavaScript
var xCoordinate;
var yCoordinate;

$(document).on('mousemove', function (e) {
    xCoordinate = e.pageX;
    yCoordinate = e.pageY;
});
 
Share this answer
 
Comments
ravi1989h 17-May-13 6:28am    
thanks ..? But how to make dropdown below buttons ? ?
vinay_sinha 17-May-13 6:54am    
hey, you can check the latest answer i have submitted
ravi1989h 17-May-13 6:30am    
how to make drop down using this var select = document.createElement("select"); and how to set this dropdown on this position .
this code can help you to set the position(where xCoordinate & yCoordinate you can find from the above answer ) like this:
JavaScript
document.getElementById("yourDropDownID").style.top = yCoordinate + "px";
document.getElementById("yourDropDownID").style.left = xCoordinate + "px";


Also you want to create those dropdowns, this [^] can help you, Best of Luck :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900