Click here to Skip to main content
15,925,602 members
Home / Discussions / Web Development
   

Web Development

 
AnswerRe: CSS Layout vs. Table Layout Pin
Guffa23-May-06 23:58
Guffa23-May-06 23:58 
Questionprint Pin
militiaware22-May-06 2:31
militiaware22-May-06 2:31 
AnswerRe: print Pin
KrIstOfK22-May-06 2:45
KrIstOfK22-May-06 2:45 
QuestionClose Right Click On Flash Pin
mehrdadc4821-May-06 20:53
mehrdadc4821-May-06 20:53 
QuestionPrinting.. Pin
deepaks321-May-06 20:13
deepaks321-May-06 20:13 
AnswerRe: Printing.. Pin
KrIstOfK21-May-06 21:36
KrIstOfK21-May-06 21:36 
GeneralRe: Printing.. Pin
deepaks322-May-06 0:44
deepaks322-May-06 0:44 
QuestionJavascript code cant draw and find mouse coordinates [modified] Pin
KaKa'21-May-06 16:42
KaKa'21-May-06 16:42 
Hi,

There is a problem with the javascript below. I cant find where the problem is.

I have to draw a rectangle by dragging the mouse. Also, when the mouse is first clicked before dragging and released after dragging, the mouse coordinates will be displayed.

I had 2 seperate scripts. One which draws the rectangle when the mouse is dragged and the other displays mouse coordinates when the mouse is clicked and released. Both can work individually but when I combine them, there is a problem. The rectangle can be drawn but the mouse coordinates are not displayed.






<script type="text/JavaScript">

var d;var posx;var posy;var initx=false;var inity=false;var click = 0;

function getMouse(obj,e){
posx=0;posy=0;
var ev=(!e)?window.event:e;//Moz:IE
if (ev.pageX){//Moz
posx=ev.pageX+window.pageXOffset;
posy=ev.pageY+window.pageYOffset;
}
else if(ev.clientX){//IE
posx=ev.clientX+document.body.scrollLeft;
posy=ev.clientY+document.body.scrollTop;
}
else{return false}//old browsers

var target = (e && e.target) || (event && event.srcElement);

if(target.id=='Canvas'){
obj.onmousedown=function(){
initx=posx; inity=posy;
d = document.createElement('div');
d.className='square'
d.style.left=initx+'px';d.style.top=inity+'px';
document.getElementsByTagName('body')[0].appendChild(d)
if(click == 0){
click = 1;
document.getElementByID('xbefore').value=posx;
document.getElementByID('ybefore').value=posy;
}
}

obj.onmouseup=function(){
if(click == 1){
click = 0;
document.getElementByID('xafter').value=posx;
document.getElementByID('yafter').value=posy;
}
initx=false;inity=false;
}

if(initx){
d.style.width=Math.abs(posx-initx)+'px';d.style.height=Math.abs(posy-inity)+'px';
d.style.left=posx-initx<0?posx+'px':initx+'px';
d.style.top=posy-inity<0?posy+'px':inity+'px';
}
}
else{return false}
}
document.onmousemove=function(event){
getMouse(document,event);
}




Before

X:     
Y:

After:

X:     
Y:


Could anyone help to see where the problem is?

I can post the 2 individual working scripts if needed


-- modified at 22:47 Sunday 21st May, 2006

QuestionSite Map Path Pin
Naveed Kamboh21-May-06 10:00
Naveed Kamboh21-May-06 10:00 
AnswerRe: Site Map Path Pin
NeverHeardOfMe23-May-06 1:11
NeverHeardOfMe23-May-06 1:11 
GeneralRe: Site Map Path Pin
Naveed Kamboh23-May-06 1:26
Naveed Kamboh23-May-06 1:26 
QuestionWebservice Pin
cuongcntt200221-May-06 7:53
cuongcntt200221-May-06 7:53 
QuestionSetting up Cassini Pin
Megan Forbes21-May-06 2:47
Megan Forbes21-May-06 2:47 
GeneralRe: Setting up Cassini [modified] Pin
User 171649221-May-06 12:53
professionalUser 171649221-May-06 12:53 
GeneralRe: Setting up Cassini [modified] Pin
Megan Forbes22-May-06 0:05
Megan Forbes22-May-06 0:05 
GeneralRe: Setting up Cassini [modified] Pin
User 171649222-May-06 12:37
professionalUser 171649222-May-06 12:37 
Questionreading data from .net web service using html Pin
Fu Manchu19-May-06 11:18
Fu Manchu19-May-06 11:18 
GeneralRe: reading data from .net web service using html [modifed] Pin
User 171649220-May-06 3:18
professionalUser 171649220-May-06 3:18 
QuestionOnChange Event Pin
Bassam Saoud19-May-06 4:20
Bassam Saoud19-May-06 4:20 
Questiondropdownlist with manual text entry Pin
moazzamahmed19-May-06 3:50
moazzamahmed19-May-06 3:50 
AnswerRe: dropdownlist with manual text entry Pin
Paddy Boyd19-May-06 4:36
Paddy Boyd19-May-06 4:36 
GeneralRe: dropdownlist with manual text entry Pin
moazzamahmed21-May-06 18:29
moazzamahmed21-May-06 18:29 
Questionbulk of data load problem Pin
Irfan.x19-May-06 3:03
Irfan.x19-May-06 3:03 
Questioncss problems Pin
Roger Alsing19-May-06 1:30
Roger Alsing19-May-06 1:30 
AnswerRe: css problems Pin
User 171649219-May-06 2:53
professionalUser 171649219-May-06 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.