Click here to Skip to main content
11,636,985 members (71,629 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Hi everybody,

Would you please help me. Do you know how I can draw a line with javascript in asp.net? Here is my code I can't make work:


<script type="text/JavaScript" src="jsDraw2D.js">
        function draw()
        {
            var gr = new jsGraphics(document.getElementById("some_div_id"));
            var col = new jsColor("Red");
            var pen = new jsPen(col, 2);
            var pt1 = new jsPoint(20, 30);
            var pt2 = new jsPoint(120, 230);
            gr.drawLine(pen, pt1, pt2);
        }
</script>
and here is my div in which i want to draw a line "onmousedown" event:
<div id="some_div_id" style="position:relative;width:600px;height:300px;background:Silver;" onmousedown="draw();"></div>

I was advised to download this &quot;jsDraw2D.js&quot; javascript library, but it didn't work, it was not even recognized by compiler as I saw.

So help me please if you can, I'm new at all in asp.net and jscript.
Posted 1-Dec-10 23:34pm
Edited 1-Dec-10 23:44pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi!

You have a very subtle error in your code. You need to include the jsDraw2D.js in a separate script tag that is included in the head section of your html like in my complete example below:

<html>
	<head>
		<title>Hallo???</title>
		<script type="text/javascript" src="./js/jsDraw2D.js"></script>
		<script type="text/javascript">
			function hello()
			{
				alert("Manfred was here!");
			}
			function draw()
			{
				var gr = new jsGraphics(document.getElementById("some_div_id"));
				var col = new jsColor("Red");
				var pen = new jsPen(col, 2);
				var pt1 = new jsPoint(20, 30);
				var pt2 = new jsPoint(120, 230);
				gr.drawLine(pen, pt1, pt2);
			}
		</script>
	</head>
	<body>
	and here is my div in which i want to draw a line "onmousedown" event:
	<div id="some_div_id" style="position:relative;width:600px;height:300px;background:Silver;border: 2px red solid" onmousedown="draw();">
	</div>
	</body>
</html>
</body></html>


Cheers

Manfred
  Permalink  
Comments
mmeliqyan at 3-Dec-10 1:15am
   
Thank you very much dear Manfred, now it works!
ManfredRBihy at 3-Dec-10 1:16am
   
Glad I could help you!

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

  Print Answers RSS
0 stibee 313
1 jyo.net 295
2 OriginalGriff 263
3 Sergey Alexandrovich Kryukov 240
4 Suvendu Shekhar Giri 225
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,493
2 Mika Wendelius 6,909
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 2 Dec 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100