Click here to Skip to main content
12,302,287 members (51,210 online)
Rate this:
 
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
Slacker00793.9K
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 3-Dec-10 1:15am
   
Thank you very much dear Manfred, now it works!
ManfredRBihy 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 2 Dec 2010
Copyright © CodeProject, 1999-2016
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