IE9 doesnt update js globals from function
- may
- Proficient


- Joined: Dec 25, 2004
- Posts: 328
- Loc: Holland [NL]
- Status: Offline
Hi Guys,
I have this little project going in which I use HTTPRequest to draw into an image using a PHP backend. In the Ajax frontend I use a select dropdown in conjunction with onchange="function" to update a JS global var. All is working as expected in Firefox without any errors, except in IE.
Here is the js.
// Are we IE
var isIE = document.all?true:false;
// Declare some vars
var aDiv;
var posX; // This var is used to store the mouse X position
var posY; // This var is used to store the mouse Y position
var Color = 'blue'; // Sets the filled eclipse color
var Size = 10; // Sets the eclipse size in px
var xmlhttp; // We use ajax to update the image remotely
if(!e) var e = window.event;
// initialize the AJAX http request object
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
if(isIE){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
// Function that catches the mouse coords.
function getCoords(e){
if(!isIE){
posX = e.offsetX?(e.offsetX):e.pageX-document.getElementById(aDiv).offsetLeft;
posY = e.offsetY?(e.offsetY):e.pageY-document.getElementById(aDiv).offsetTop;
}else{
posX = event.offsetX + document.body.scrollLeft;
posY = event.offsetY + document.body.scrollTop;
}
return true;
}
// Use the remote PHP lib to add a dot from the image
function putDot(imgId, Id, color){
var obj = document.getElementById(imgId);
var url = 'rendering_engine.php?imgid='+Id+'&posx='+posX+'&posy='+posY+'&action=add&color='+Color+'&size='+Size+'&height='+obj.height+'&width='+obj.width;
xmlhttp.open('GET',url,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
ldImage(imgId, Id);
}
}
}
function ldImage(imgId, Id){
var obj = document.getElementById(imgId);
var date = new Date();
//alert('height:'+obj.height+'width:'+obj.width);
var url = 'rendering_engine.php?imgid='+Id+'&action=show&posx='+posX+'&posy='+posY+'&height='+obj.height+'&width='+obj.width+'&'+date.getTime();
obj.src = url;
}
function setColor(val){ Color = val; }
function setSize(val){ Size = val; }
function MouseCaptureLoc(activeDiv){ aDiv = activeDiv; }
document.onmousemove = getCoords;
For some reason when the function setColor() is called, it results in an undefined js Global var. Anyone any clue on how i can solve this?
The function is called using the following HTML.
Any help is much appreciated.
TIA, May
I have this little project going in which I use HTTPRequest to draw into an image using a PHP backend. In the Ajax frontend I use a select dropdown in conjunction with onchange="function" to update a JS global var. All is working as expected in Firefox without any errors, except in IE.
Here is the js.
JAVASCRIPT Code: [ Select ]
// Are we IE
var isIE = document.all?true:false;
// Declare some vars
var aDiv;
var posX; // This var is used to store the mouse X position
var posY; // This var is used to store the mouse Y position
var Color = 'blue'; // Sets the filled eclipse color
var Size = 10; // Sets the eclipse size in px
var xmlhttp; // We use ajax to update the image remotely
if(!e) var e = window.event;
// initialize the AJAX http request object
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
if(isIE){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
// Function that catches the mouse coords.
function getCoords(e){
if(!isIE){
posX = e.offsetX?(e.offsetX):e.pageX-document.getElementById(aDiv).offsetLeft;
posY = e.offsetY?(e.offsetY):e.pageY-document.getElementById(aDiv).offsetTop;
}else{
posX = event.offsetX + document.body.scrollLeft;
posY = event.offsetY + document.body.scrollTop;
}
return true;
}
// Use the remote PHP lib to add a dot from the image
function putDot(imgId, Id, color){
var obj = document.getElementById(imgId);
var url = 'rendering_engine.php?imgid='+Id+'&posx='+posX+'&posy='+posY+'&action=add&color='+Color+'&size='+Size+'&height='+obj.height+'&width='+obj.width;
xmlhttp.open('GET',url,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
ldImage(imgId, Id);
}
}
}
function ldImage(imgId, Id){
var obj = document.getElementById(imgId);
var date = new Date();
//alert('height:'+obj.height+'width:'+obj.width);
var url = 'rendering_engine.php?imgid='+Id+'&action=show&posx='+posX+'&posy='+posY+'&height='+obj.height+'&width='+obj.width+'&'+date.getTime();
obj.src = url;
}
function setColor(val){ Color = val; }
function setSize(val){ Size = val; }
function MouseCaptureLoc(activeDiv){ aDiv = activeDiv; }
document.onmousemove = getCoords;
- // Are we IE
- var isIE = document.all?true:false;
- // Declare some vars
- var aDiv;
- var posX; // This var is used to store the mouse X position
- var posY; // This var is used to store the mouse Y position
- var Color = 'blue'; // Sets the filled eclipse color
- var Size = 10; // Sets the eclipse size in px
- var xmlhttp; // We use ajax to update the image remotely
- if(!e) var e = window.event;
- // initialize the AJAX http request object
- if(window.XMLHttpRequest){
- xmlhttp = new XMLHttpRequest();
- }else{
- if(isIE){
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
- // Function that catches the mouse coords.
- function getCoords(e){
- if(!isIE){
- posX = e.offsetX?(e.offsetX):e.pageX-document.getElementById(aDiv).offsetLeft;
- posY = e.offsetY?(e.offsetY):e.pageY-document.getElementById(aDiv).offsetTop;
- }else{
- posX = event.offsetX + document.body.scrollLeft;
- posY = event.offsetY + document.body.scrollTop;
- }
- return true;
- }
- // Use the remote PHP lib to add a dot from the image
- function putDot(imgId, Id, color){
- var obj = document.getElementById(imgId);
- var url = 'rendering_engine.php?imgid='+Id+'&posx='+posX+'&posy='+posY+'&action=add&color='+Color+'&size='+Size+'&height='+obj.height+'&width='+obj.width;
- xmlhttp.open('GET',url,true);
- xmlhttp.send();
- xmlhttp.onreadystatechange=function(){
- if(xmlhttp.readyState==4 && xmlhttp.status==200){
- ldImage(imgId, Id);
- }
- }
- }
- function ldImage(imgId, Id){
- var obj = document.getElementById(imgId);
- var date = new Date();
- //alert('height:'+obj.height+'width:'+obj.width);
- var url = 'rendering_engine.php?imgid='+Id+'&action=show&posx='+posX+'&posy='+posY+'&height='+obj.height+'&width='+obj.width+'&'+date.getTime();
- obj.src = url;
- }
- function setColor(val){ Color = val; }
- function setSize(val){ Size = val; }
- function MouseCaptureLoc(activeDiv){ aDiv = activeDiv; }
- document.onmousemove = getCoords;
For some reason when the function setColor() is called, it results in an undefined js Global var. Anyone any clue on how i can solve this?
The function is called using the following HTML.
HTML Code: [ Select ]
<div>
<select onchange="setColor(value)">
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
</div>
<select onchange="setColor(value)">
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
</div>
- <div>
- <select onchange="setColor(value)">
- <option>blue</option>
- <option>green</option>
- <option>red</option>
- <option>gray</option>
- <option>white</option>
- <option>clean up</option>
- </select>
- <select onchange="setSize(value)">
- <option>10</option>
- <option>15</option>
- <option>20</option>
- <option>25</option>
- <option>30</option>
- <option>35</option>
- </select>
- </div>
Any help is much appreciated.
TIA, May
1 + 1 = 10 + 1 = 11 + 11 = 110
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
June 7th, 2011, 1:24 pm
- WritingBadCode
- Graduate


- Joined: Apr 28, 2011
- Posts: 214
- Loc: Sweden
- Status: Offline
I don't know if this could have something to do with it but when testing the javascript you provided with this:
I noted that "value" or "val" as its renamed holds no value in IE.
I changed the functions to look like this just for testing purpose:
IE sent a EMPTY alert while Chrome and FireFox sent the value selected.
EDIT: I misread your post. I see you had that figured out. Lol. Sorry.
Here is some ugly looking code that will work in both IE and the others (just for color thing) to give you an idea :
Instead of
Try:
This assumes that you change the HTML code to this:
Making 2 changes, giving it a ID value and onchange won't pass any values.
Code: [ Select ]
<select onchange="setColor(value)">
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
- <select onchange="setColor(value)">
- <option>blue</option>
- <option>green</option>
- <option>red</option>
- <option>gray</option>
- <option>white</option>
- <option>clean up</option>
- </select>
- <select onchange="setSize(value)">
- <option>10</option>
- <option>15</option>
- <option>20</option>
- <option>25</option>
- <option>30</option>
- <option>35</option>
- </select>
I noted that "value" or "val" as its renamed holds no value in IE.
I changed the functions to look like this just for testing purpose:
Code: [ Select ]
function setColor(val){ alert(val); }
function setSize(val){ alert(val); }
function setSize(val){ alert(val); }
- function setColor(val){ alert(val); }
- function setSize(val){ alert(val); }
IE sent a EMPTY alert while Chrome and FireFox sent the value selected.
EDIT: I misread your post. I see you had that figured out. Lol. Sorry.
Here is some ugly looking code that will work in both IE and the others (just for color thing) to give you an idea :
Instead of
Code: [ Select ]
function setColor(val){ Color = val; }
Try:
Code: [ Select ]
function setColor()
{
var values = document.getElementById("colorChange");
var count = values.length;
for(var n = 0; n < count; n++)
{
if (values.options[n].selected)
{
Color = values.options[n].innerHTML;
alert(Color);
}
}
}
{
var values = document.getElementById("colorChange");
var count = values.length;
for(var n = 0; n < count; n++)
{
if (values.options[n].selected)
{
Color = values.options[n].innerHTML;
alert(Color);
}
}
}
- function setColor()
- {
- var values = document.getElementById("colorChange");
- var count = values.length;
- for(var n = 0; n < count; n++)
- {
- if (values.options[n].selected)
- {
- Color = values.options[n].innerHTML;
- alert(Color);
- }
- }
- }
This assumes that you change the HTML code to this:
Code: [ Select ]
<select id="colorChange" onchange="setColor()">
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
- <select id="colorChange" onchange="setColor()">
- <option>blue</option>
- <option>green</option>
- <option>red</option>
- <option>gray</option>
- <option>white</option>
- <option>clean up</option>
- </select>
- <select onchange="setSize(value)">
- <option>10</option>
- <option>15</option>
- <option>20</option>
- <option>25</option>
- <option>30</option>
- <option>35</option>
- </select>
Making 2 changes, giving it a ID value and onchange won't pass any values.
- may
- Proficient


- Joined: Dec 25, 2004
- Posts: 328
- Loc: Holland [NL]
- Status: Offline
Yeah, I also noted that IE does not pass the value like mozilla like browser. Your solution 'ugly' as you name it
looks rather lumbersum, but if it works ill go with that.
I am a bit worried about looping through each value, which might become a problem with large select lists and poor client performance, so i think ill make your code even uglier by testing the browser type
Any way, if it works...
Oh, yeah before I forget the most important part...
THX for the suggested solution
I am a bit worried about looping through each value, which might become a problem with large select lists and poor client performance, so i think ill make your code even uglier by testing the browser type
Any way, if it works...
Oh, yeah before I forget the most important part...
THX for the suggested solution
1 + 1 = 10 + 1 = 11 + 11 = 110
- WritingBadCode
- Graduate


- Joined: Apr 28, 2011
- Posts: 214
- Loc: Sweden
- Status: Offline
As you say there is probably better ways to do this especially if the list gets big.
If you find a better solution please don't feel bad for sharing. =)
One minor thing you can do if you don't like it looping through everything is adding a break;
function setColor()
{
var values = document.getElementById("colorChange");
var count = values.length;
for(var n = 0; n < count; n++)
{
if (values.options[n].selected)
{
Color = values.options[n].innerHTML;
break;
}
}
}
If the user choses one of the first values then the looping will stop there, saving some processing? IDK.
If you find a better solution please don't feel bad for sharing. =)
One minor thing you can do if you don't like it looping through everything is adding a break;
Code: [ Select ]
function setColor()
{
var values = document.getElementById("colorChange");
var count = values.length;
for(var n = 0; n < count; n++)
{
if (values.options[n].selected)
{
Color = values.options[n].innerHTML;
break;
}
}
}
- function setColor()
- {
- var values = document.getElementById("colorChange");
- var count = values.length;
- for(var n = 0; n < count; n++)
- {
- if (values.options[n].selected)
- {
- Color = values.options[n].innerHTML;
- break;
- }
- }
- }
If the user choses one of the first values then the looping will stop there, saving some processing? IDK.
- may
- Proficient


- Joined: Dec 25, 2004
- Posts: 328
- Loc: Holland [NL]
- Status: Offline
- may
- Proficient


- Joined: Dec 25, 2004
- Posts: 328
- Loc: Holland [NL]
- Status: Offline
For anyone that likes to experiment with this, here is the full code 
DO NOTE THAT ITS NOT FIT (YET) FOR PRODUCTION PURPOSES. THE CODE NEEDS REFINEMENT AND OBVIOUS SECURITY CHECKS AND ESCAPES.
DO NOTE THAT ITS NOT FIT (YET) FOR PRODUCTION PURPOSES. THE CODE NEEDS REFINEMENT AND OBVIOUS SECURITY CHECKS AND ESCAPES.
HTML Code: [ Select ]
<?php
// Fetch the patient_id and Image_id
?>
<html>
<head>
<!-- Enable IE8 Standards mode -->
<meta http-equiv="X-UA-Compatible" content="IE=8" >
<script language="JavaScript">
// Are we IE
var isIE = document.all?true:false;
// Declare some vars
var aDiv;
var posX; // This var is used to store the mouse X position
var posY; // This var is used to store the mouse Y position
var Color = 'blue'; // Sets the filled eclipse color
var Size = 10; // Sets the eclipse size in px
var xmlhttp; // We use ajax to update the image remotely
// Test if event is defined, else define it.
if(!e) var e = window.event;
// initialize the AJAX http request object
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
if(isIE){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
// Function that catches the mouse coords and is called on document.mousemove.
function getCoords(e){
if(!isIE){
posX = e.offsetX?(e.offsetX):e.pageX-document.getElementById(aDiv).offsetLeft;
posY = e.offsetY?(e.offsetY):e.pageY-document.getElementById(aDiv).offsetTop;
}else{
posX = event.offsetX + document.body.scrollLeft;
posY = event.offsetY + document.body.scrollTop;
}
return true;
}
// Function that instructs php to draw a dot with the given properties on the given coords.
function putDot(imgId, Id, color){
var obj = document.getElementById(imgId);
var url = 'rendering_engine.php?imgid='+Id+'&posx='+posX+'&posy='+posY+'&action=add&color='+Color+'&size='+Size+'&height='+obj.height+'&width='+obj.width;
xmlhttp.open('GET',url,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
ldImage(imgId, Id);
}
}
}
// Function that (re)loads the image on pageload and draw activity.
function ldImage(imgId, Id){
var obj = document.getElementById(imgId);
var date = new Date();
var url = 'rendering_engine.php?imgid='+Id+'&action=show&posx='+posX+'&posy='+posY+'&height='+obj.height+'&width='+obj.width+'&'+date.getTime();
obj.src = url;
}
// Assign pattern that is supported by both IE and Mozilla.
// IE does not pass obj.value onchange like mozilla does.
// Thx to WritingBadCode on Ozzu.com
function setColor(){
var values = document.getElementById("brushColor");
var count = values.length;
for(var n = 0; n < count; n++){
if (values.options[n].selected){
Color = values.options[n].innerHTML;
}
}
}
// Assign pattern that is supported by both IE and Mozilla.
// IE does not pass obj.value onchange like mozilla does.
// Thx to WritingBadCode on Ozzu.com
function setSize(){
var values = document.getElementById("brushSize");
var count = values.length;
for(var n = 0; n < count; n++){
if (values.options[n].selected){
Size = values.options[n].innerHTML;
}
}
}
function MouseCaptureLoc(activeDiv){ aDiv = activeDiv; }
document.onmousemove = getCoords;
</script>
</head>
<body style="margin-left:50px; width:100%;" onload="ldImage('img1', 1); ldImage('img2', 2);">
<div>
<form name="brushes" id="brushes">
<select id="brushColor" onchange="setColor()">
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select id="brushSize" onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
</form>
</div>
<div>
<div style="float:left;">
<div onmouseover="MouseCaptureLoc('1')" id="1" style="float:left; border:1px solid black; background-image:url(./skeletalsystem.jpg); width:597px; height:741px;">
<img onclick="putDot('img1', '1')" id="img1" src="#" width="597" height="741">
</div>
<div onmouseover="MouseCaptureLoc('2')" id="2" style=" float:right; border:1px solid black; background-image:url(./human_organs.jpg); width:453px; height:477px;">
<img onclick="putDot('img2', '2')" id="img2" src="#" width="453" height="477" >
</div>
</div>
</body>
</html>
// Fetch the patient_id and Image_id
?>
<html>
<head>
<!-- Enable IE8 Standards mode -->
<meta http-equiv="X-UA-Compatible" content="IE=8" >
<script language="JavaScript">
// Are we IE
var isIE = document.all?true:false;
// Declare some vars
var aDiv;
var posX; // This var is used to store the mouse X position
var posY; // This var is used to store the mouse Y position
var Color = 'blue'; // Sets the filled eclipse color
var Size = 10; // Sets the eclipse size in px
var xmlhttp; // We use ajax to update the image remotely
// Test if event is defined, else define it.
if(!e) var e = window.event;
// initialize the AJAX http request object
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
if(isIE){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
// Function that catches the mouse coords and is called on document.mousemove.
function getCoords(e){
if(!isIE){
posX = e.offsetX?(e.offsetX):e.pageX-document.getElementById(aDiv).offsetLeft;
posY = e.offsetY?(e.offsetY):e.pageY-document.getElementById(aDiv).offsetTop;
}else{
posX = event.offsetX + document.body.scrollLeft;
posY = event.offsetY + document.body.scrollTop;
}
return true;
}
// Function that instructs php to draw a dot with the given properties on the given coords.
function putDot(imgId, Id, color){
var obj = document.getElementById(imgId);
var url = 'rendering_engine.php?imgid='+Id+'&posx='+posX+'&posy='+posY+'&action=add&color='+Color+'&size='+Size+'&height='+obj.height+'&width='+obj.width;
xmlhttp.open('GET',url,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
ldImage(imgId, Id);
}
}
}
// Function that (re)loads the image on pageload and draw activity.
function ldImage(imgId, Id){
var obj = document.getElementById(imgId);
var date = new Date();
var url = 'rendering_engine.php?imgid='+Id+'&action=show&posx='+posX+'&posy='+posY+'&height='+obj.height+'&width='+obj.width+'&'+date.getTime();
obj.src = url;
}
// Assign pattern that is supported by both IE and Mozilla.
// IE does not pass obj.value onchange like mozilla does.
// Thx to WritingBadCode on Ozzu.com
function setColor(){
var values = document.getElementById("brushColor");
var count = values.length;
for(var n = 0; n < count; n++){
if (values.options[n].selected){
Color = values.options[n].innerHTML;
}
}
}
// Assign pattern that is supported by both IE and Mozilla.
// IE does not pass obj.value onchange like mozilla does.
// Thx to WritingBadCode on Ozzu.com
function setSize(){
var values = document.getElementById("brushSize");
var count = values.length;
for(var n = 0; n < count; n++){
if (values.options[n].selected){
Size = values.options[n].innerHTML;
}
}
}
function MouseCaptureLoc(activeDiv){ aDiv = activeDiv; }
document.onmousemove = getCoords;
</script>
</head>
<body style="margin-left:50px; width:100%;" onload="ldImage('img1', 1); ldImage('img2', 2);">
<div>
<form name="brushes" id="brushes">
<select id="brushColor" onchange="setColor()">
<option>blue</option>
<option>green</option>
<option>red</option>
<option>gray</option>
<option>white</option>
<option>clean up</option>
</select>
<select id="brushSize" onchange="setSize(value)">
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>35</option>
</select>
</form>
</div>
<div>
<div style="float:left;">
<div onmouseover="MouseCaptureLoc('1')" id="1" style="float:left; border:1px solid black; background-image:url(./skeletalsystem.jpg); width:597px; height:741px;">
<img onclick="putDot('img1', '1')" id="img1" src="#" width="597" height="741">
</div>
<div onmouseover="MouseCaptureLoc('2')" id="2" style=" float:right; border:1px solid black; background-image:url(./human_organs.jpg); width:453px; height:477px;">
<img onclick="putDot('img2', '2')" id="img2" src="#" width="453" height="477" >
</div>
</div>
</body>
</html>
- <?php
- // Fetch the patient_id and Image_id
- ?>
- <html>
- <head>
- <!-- Enable IE8 Standards mode -->
- <meta http-equiv="X-UA-Compatible" content="IE=8" >
- <script language="JavaScript">
- // Are we IE
- var isIE = document.all?true:false;
- // Declare some vars
- var aDiv;
- var posX; // This var is used to store the mouse X position
- var posY; // This var is used to store the mouse Y position
- var Color = 'blue'; // Sets the filled eclipse color
- var Size = 10; // Sets the eclipse size in px
- var xmlhttp; // We use ajax to update the image remotely
- // Test if event is defined, else define it.
- if(!e) var e = window.event;
- // initialize the AJAX http request object
- if(window.XMLHttpRequest){
- xmlhttp = new XMLHttpRequest();
- }else{
- if(isIE){
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
- // Function that catches the mouse coords and is called on document.mousemove.
- function getCoords(e){
- if(!isIE){
- posX = e.offsetX?(e.offsetX):e.pageX-document.getElementById(aDiv).offsetLeft;
- posY = e.offsetY?(e.offsetY):e.pageY-document.getElementById(aDiv).offsetTop;
- }else{
- posX = event.offsetX + document.body.scrollLeft;
- posY = event.offsetY + document.body.scrollTop;
- }
- return true;
- }
- // Function that instructs php to draw a dot with the given properties on the given coords.
- function putDot(imgId, Id, color){
- var obj = document.getElementById(imgId);
- var url = 'rendering_engine.php?imgid='+Id+'&posx='+posX+'&posy='+posY+'&action=add&color='+Color+'&size='+Size+'&height='+obj.height+'&width='+obj.width;
- xmlhttp.open('GET',url,true);
- xmlhttp.send();
- xmlhttp.onreadystatechange=function(){
- if(xmlhttp.readyState==4 && xmlhttp.status==200){
- ldImage(imgId, Id);
- }
- }
- }
- // Function that (re)loads the image on pageload and draw activity.
- function ldImage(imgId, Id){
- var obj = document.getElementById(imgId);
- var date = new Date();
- var url = 'rendering_engine.php?imgid='+Id+'&action=show&posx='+posX+'&posy='+posY+'&height='+obj.height+'&width='+obj.width+'&'+date.getTime();
- obj.src = url;
- }
- // Assign pattern that is supported by both IE and Mozilla.
- // IE does not pass obj.value onchange like mozilla does.
- // Thx to WritingBadCode on Ozzu.com
- function setColor(){
- var values = document.getElementById("brushColor");
- var count = values.length;
- for(var n = 0; n < count; n++){
- if (values.options[n].selected){
- Color = values.options[n].innerHTML;
- }
- }
- }
- // Assign pattern that is supported by both IE and Mozilla.
- // IE does not pass obj.value onchange like mozilla does.
- // Thx to WritingBadCode on Ozzu.com
- function setSize(){
- var values = document.getElementById("brushSize");
- var count = values.length;
- for(var n = 0; n < count; n++){
- if (values.options[n].selected){
- Size = values.options[n].innerHTML;
- }
- }
- }
- function MouseCaptureLoc(activeDiv){ aDiv = activeDiv; }
- document.onmousemove = getCoords;
- </script>
- </head>
- <body style="margin-left:50px; width:100%;" onload="ldImage('img1', 1); ldImage('img2', 2);">
- <div>
- <form name="brushes" id="brushes">
- <select id="brushColor" onchange="setColor()">
- <option>blue</option>
- <option>green</option>
- <option>red</option>
- <option>gray</option>
- <option>white</option>
- <option>clean up</option>
- </select>
- <select id="brushSize" onchange="setSize(value)">
- <option>10</option>
- <option>15</option>
- <option>20</option>
- <option>25</option>
- <option>30</option>
- <option>35</option>
- </select>
- </form>
- </div>
- <div>
- <div style="float:left;">
- <div onmouseover="MouseCaptureLoc('1')" id="1" style="float:left; border:1px solid black; background-image:url(./skeletalsystem.jpg); width:597px; height:741px;">
- <img onclick="putDot('img1', '1')" id="img1" src="#" width="597" height="741">
- </div>
- <div onmouseover="MouseCaptureLoc('2')" id="2" style=" float:right; border:1px solid black; background-image:url(./human_organs.jpg); width:453px; height:477px;">
- <img onclick="putDot('img2', '2')" id="img2" src="#" width="453" height="477" >
- </div>
- </div>
- </body>
- </html>
PHP Code: [ Select ]
<?php
// Connect to the database
if($dblink = mysql_connect('127.0.0.1','root','password')){
mysql_select_db('test', $dblink);
}else{
exit;
}
// fetch all post/gets.
if(isset($_POST{'action'}) || isset($_GET{'action'})){
if(isset($_POST{'action'})){
foreach($_POST as $key => $value){
$$key = $value;
}
}else{
foreach($_GET as $key => $value){
$$key = $value;
}
}
}else{
exit;
}
// Determ what function to call //
if(isset($action)){
if($action == 'add'){
if(isset($imgid)){
add_eclipse($posx, $posy, $imgid, $color, $size, $width, $height);
}else{
echo 'false';
}
}elseif($action == 'show'){
if(isset($imgid)){
show_image($posx, $posy, $imgid, $width, $height);
}else{
echo 'false';
}
}else{
echo 'false';
}
}
function add_eclipse($x, $y, $id, $color = false, $size = false, $width = false, $height = false){
if(isset($id)){
$sql = "select * from images where id = '$id'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if($row){
$img = imagecreatefromstring($row{'image_bin'});
$new = false;
}else{
// New image //
$img = imagecreatetruecolor($width, $height);
$new = true;
}
}
// Enable alpha blending (requires GD2.0)
imageantialias($img, true);
// Color Pallete
$pallet{'black'} = imagecolorallocate($img, 2, 2, 2);;
$pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
$pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
$pallet{'red'} = imagecolorallocate($img, 255, 0, 0);
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
$pallet{'blue'} = imagecolorallocate($img, 50, 50, 200);
$pallet{'white'} = imagecolorallocate($img, 255, 255, 255);
$pallet{'gray'} = imagecolorallocate($img, 128, 128, 128);
// BG
ImageColorTransparent($img, $pallet{'transparant'});
// Add the eclipse
if(!isset($color)){ $color = 'red'; }
if(!isset($size)){ $size = 20;}
if($color != 'clean up'){
imagefilledellipse($img, $x, $y, $size+3, $size+3, $pallet{'black'});
}
imagefilledellipse($img, $x, $y, $size, $size, $pallet{$color});
//imagefilledellipse($img, $x-5, $y, 10, 10, $pallet{'transparent'});
// Get the raw image using an output buffer (ob)
ob_start();
imagepng($img);
$unsave = ob_get_contents();
ob_end_clean();
// Create a hex tring out of the raw stream
$save = addslashes($unsave);
if($new){
$sql = "insert into images(image_ext, image_bin) values('png','".$save."')";
}else{
$sql = "update images set image_bin='".$save."' where id='$id'";
}
if(mysql_query($sql)){
header("Content-type: image/png");
echo $unsave;
}else{
echo mysql_error();
echo 'false';
}
}
function show_image($posx=false, $posy=false, $id, $width = false, $height = false){
if(isset($id)){
if($posx == 'undefined'){
$posx = 'undef';
$posy = 'undef';
}
$sql = "select * from images where id = '$id'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if($row){
// Create a image canvas
$img = imagecreatefromstring($row{'image_bin'});
// Create the debugging string
$pos = "ID=$id,X=$posx,Y=$posy";
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
imagestring($img, 3, 10, 2, 'Bestaande anamnese', $pallet{'green'});
imagestring($img, 3, 10, 15, $pos, $pallet{'green'});
header("Content-type: image/png");
imagepng($img);
//echo $row{'image_bin'};
}else{
$img = imagecreatetruecolor($width, $height);
// Color Pallete
$pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
$pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
// BG
ImageColorTransparent($img, $pallet{'transparant'});
imagestring($img, 3, 10, 2, "nieuwe anamnese w:$width h:$height", $pallet{'green'});
header("Content-type: image/png");
imagepng($img);
}
}else{
$img = imagecreatetruecolor(401, 844);
// Color Pallete
$pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
$pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
// BG
ImageColorTransparent($img, $pallet{'transparant'});
imagestring($img, 3, 10, 2, 'nieuwe anamnese', $pallet{'green'});
header("Content-type: image/png");
imagepng($img);
}
}
?>
// Connect to the database
if($dblink = mysql_connect('127.0.0.1','root','password')){
mysql_select_db('test', $dblink);
}else{
exit;
}
// fetch all post/gets.
if(isset($_POST{'action'}) || isset($_GET{'action'})){
if(isset($_POST{'action'})){
foreach($_POST as $key => $value){
$$key = $value;
}
}else{
foreach($_GET as $key => $value){
$$key = $value;
}
}
}else{
exit;
}
// Determ what function to call //
if(isset($action)){
if($action == 'add'){
if(isset($imgid)){
add_eclipse($posx, $posy, $imgid, $color, $size, $width, $height);
}else{
echo 'false';
}
}elseif($action == 'show'){
if(isset($imgid)){
show_image($posx, $posy, $imgid, $width, $height);
}else{
echo 'false';
}
}else{
echo 'false';
}
}
function add_eclipse($x, $y, $id, $color = false, $size = false, $width = false, $height = false){
if(isset($id)){
$sql = "select * from images where id = '$id'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if($row){
$img = imagecreatefromstring($row{'image_bin'});
$new = false;
}else{
// New image //
$img = imagecreatetruecolor($width, $height);
$new = true;
}
}
// Enable alpha blending (requires GD2.0)
imageantialias($img, true);
// Color Pallete
$pallet{'black'} = imagecolorallocate($img, 2, 2, 2);;
$pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
$pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
$pallet{'red'} = imagecolorallocate($img, 255, 0, 0);
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
$pallet{'blue'} = imagecolorallocate($img, 50, 50, 200);
$pallet{'white'} = imagecolorallocate($img, 255, 255, 255);
$pallet{'gray'} = imagecolorallocate($img, 128, 128, 128);
// BG
ImageColorTransparent($img, $pallet{'transparant'});
// Add the eclipse
if(!isset($color)){ $color = 'red'; }
if(!isset($size)){ $size = 20;}
if($color != 'clean up'){
imagefilledellipse($img, $x, $y, $size+3, $size+3, $pallet{'black'});
}
imagefilledellipse($img, $x, $y, $size, $size, $pallet{$color});
//imagefilledellipse($img, $x-5, $y, 10, 10, $pallet{'transparent'});
// Get the raw image using an output buffer (ob)
ob_start();
imagepng($img);
$unsave = ob_get_contents();
ob_end_clean();
// Create a hex tring out of the raw stream
$save = addslashes($unsave);
if($new){
$sql = "insert into images(image_ext, image_bin) values('png','".$save."')";
}else{
$sql = "update images set image_bin='".$save."' where id='$id'";
}
if(mysql_query($sql)){
header("Content-type: image/png");
echo $unsave;
}else{
echo mysql_error();
echo 'false';
}
}
function show_image($posx=false, $posy=false, $id, $width = false, $height = false){
if(isset($id)){
if($posx == 'undefined'){
$posx = 'undef';
$posy = 'undef';
}
$sql = "select * from images where id = '$id'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if($row){
// Create a image canvas
$img = imagecreatefromstring($row{'image_bin'});
// Create the debugging string
$pos = "ID=$id,X=$posx,Y=$posy";
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
imagestring($img, 3, 10, 2, 'Bestaande anamnese', $pallet{'green'});
imagestring($img, 3, 10, 15, $pos, $pallet{'green'});
header("Content-type: image/png");
imagepng($img);
//echo $row{'image_bin'};
}else{
$img = imagecreatetruecolor($width, $height);
// Color Pallete
$pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
$pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
// BG
ImageColorTransparent($img, $pallet{'transparant'});
imagestring($img, 3, 10, 2, "nieuwe anamnese w:$width h:$height", $pallet{'green'});
header("Content-type: image/png");
imagepng($img);
}
}else{
$img = imagecreatetruecolor(401, 844);
// Color Pallete
$pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
$pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
$pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
// BG
ImageColorTransparent($img, $pallet{'transparant'});
imagestring($img, 3, 10, 2, 'nieuwe anamnese', $pallet{'green'});
header("Content-type: image/png");
imagepng($img);
}
}
?>
- <?php
- // Connect to the database
- if($dblink = mysql_connect('127.0.0.1','root','password')){
- mysql_select_db('test', $dblink);
- }else{
- exit;
- }
- // fetch all post/gets.
- if(isset($_POST{'action'}) || isset($_GET{'action'})){
- if(isset($_POST{'action'})){
- foreach($_POST as $key => $value){
- $$key = $value;
- }
- }else{
- foreach($_GET as $key => $value){
- $$key = $value;
- }
- }
- }else{
- exit;
- }
- // Determ what function to call //
- if(isset($action)){
- if($action == 'add'){
- if(isset($imgid)){
- add_eclipse($posx, $posy, $imgid, $color, $size, $width, $height);
- }else{
- echo 'false';
- }
- }elseif($action == 'show'){
- if(isset($imgid)){
- show_image($posx, $posy, $imgid, $width, $height);
- }else{
- echo 'false';
- }
- }else{
- echo 'false';
- }
- }
- function add_eclipse($x, $y, $id, $color = false, $size = false, $width = false, $height = false){
- if(isset($id)){
- $sql = "select * from images where id = '$id'";
- $result = mysql_query($sql);
- $row = mysql_fetch_assoc($result);
- if($row){
- $img = imagecreatefromstring($row{'image_bin'});
- $new = false;
- }else{
- // New image //
- $img = imagecreatetruecolor($width, $height);
- $new = true;
- }
- }
- // Enable alpha blending (requires GD2.0)
- imageantialias($img, true);
- // Color Pallete
- $pallet{'black'} = imagecolorallocate($img, 2, 2, 2);;
- $pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
- $pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
- $pallet{'red'} = imagecolorallocate($img, 255, 0, 0);
- $pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
- $pallet{'blue'} = imagecolorallocate($img, 50, 50, 200);
- $pallet{'white'} = imagecolorallocate($img, 255, 255, 255);
- $pallet{'gray'} = imagecolorallocate($img, 128, 128, 128);
- // BG
- ImageColorTransparent($img, $pallet{'transparant'});
- // Add the eclipse
- if(!isset($color)){ $color = 'red'; }
- if(!isset($size)){ $size = 20;}
- if($color != 'clean up'){
- imagefilledellipse($img, $x, $y, $size+3, $size+3, $pallet{'black'});
- }
- imagefilledellipse($img, $x, $y, $size, $size, $pallet{$color});
- //imagefilledellipse($img, $x-5, $y, 10, 10, $pallet{'transparent'});
- // Get the raw image using an output buffer (ob)
- ob_start();
- imagepng($img);
- $unsave = ob_get_contents();
- ob_end_clean();
- // Create a hex tring out of the raw stream
- $save = addslashes($unsave);
- if($new){
- $sql = "insert into images(image_ext, image_bin) values('png','".$save."')";
- }else{
- $sql = "update images set image_bin='".$save."' where id='$id'";
- }
- if(mysql_query($sql)){
- header("Content-type: image/png");
- echo $unsave;
- }else{
- echo mysql_error();
- echo 'false';
- }
- }
- function show_image($posx=false, $posy=false, $id, $width = false, $height = false){
- if(isset($id)){
- if($posx == 'undefined'){
- $posx = 'undef';
- $posy = 'undef';
- }
- $sql = "select * from images where id = '$id'";
- $result = mysql_query($sql);
- $row = mysql_fetch_assoc($result);
- if($row){
- // Create a image canvas
- $img = imagecreatefromstring($row{'image_bin'});
- // Create the debugging string
- $pos = "ID=$id,X=$posx,Y=$posy";
- $pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
- imagestring($img, 3, 10, 2, 'Bestaande anamnese', $pallet{'green'});
- imagestring($img, 3, 10, 15, $pos, $pallet{'green'});
- header("Content-type: image/png");
- imagepng($img);
- //echo $row{'image_bin'};
- }else{
- $img = imagecreatetruecolor($width, $height);
- // Color Pallete
- $pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
- $pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
- $pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
- // BG
- ImageColorTransparent($img, $pallet{'transparant'});
- imagestring($img, 3, 10, 2, "nieuwe anamnese w:$width h:$height", $pallet{'green'});
- header("Content-type: image/png");
- imagepng($img);
- }
- }else{
- $img = imagecreatetruecolor(401, 844);
- // Color Pallete
- $pallet{'transparent'} = imagecolorallocate($img, 51, 80, 124);
- $pallet{'transparent'} = ImageColorTransparent($img, $pallet{'transparant'});
- $pallet{'green'} = imagecolorallocate($img, 0, 255, 0);
- // BG
- ImageColorTransparent($img, $pallet{'transparant'});
- imagestring($img, 3, 10, 2, 'nieuwe anamnese', $pallet{'green'});
- header("Content-type: image/png");
- imagepng($img);
- }
- }
- ?>
1 + 1 = 10 + 1 = 11 + 11 = 110
- WritingBadCode
- Graduate


- Joined: Apr 28, 2011
- Posts: 214
- Loc: Sweden
- Status: Offline
- may
- Proficient


- Joined: Dec 25, 2004
- Posts: 328
- Loc: Holland [NL]
- Status: Offline
- WritingBadCode
- Graduate


- Joined: Apr 28, 2011
- Posts: 214
- Loc: Sweden
- Status: Offline
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 9 posts
- Users browsing this forum: No registered users and 117 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
