Agilizarán no actualizar js globals de función
- may
- Proficient


- Registrado: Dic 25, 2004
- Mensajes: 328
- Loc: Holland [NL]
- Status: Offline
Hola chicos,
Tengo este pequeño curso de proyecto en que utilizo HTTPRequest para dibujar en una imagen utilizando un back-end PHP. En la interfaz de Ajax utilizo un desplegable seleccione junto con onchange = "función" para actualizar un var de JS global. Todo está funcionando como se esperaba en Firefox sin errores, excepto en IE.
Aquí está el 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;
¿Por alguna razón cuando se llama a la función setColor(), resulta en un indefinido js var mundial nadie cualquier pista sobre cómo puedo solucionarlo?
La función se llama utilizando el código HTML siguiente.
[HTML]
<div>
< seleccionar onchange="setColor(value)" >
azul de <option> </option>
verde de <option> </option>
rojo de <option> </option>
gris de <option> </option>
blanco de <option> </option>
<option> limpiar </option>
</select>
< seleccionar onchange="setSize(value)" >
<option> 10 </option>
<option> 15 </option>
<option> 20 </option>
<option> 25 </option>
<option> 30 </option>
<option> 35 </option>
</select>
</div>
[/HTML MÁS EXTERNAS]
Cualquier ayuda es muy apreciada.
TIA, mayo
Tengo este pequeño curso de proyecto en que utilizo HTTPRequest para dibujar en una imagen utilizando un back-end PHP. En la interfaz de Ajax utilizo un desplegable seleccione junto con onchange = "función" para actualizar un var de JS global. Todo está funcionando como se esperaba en Firefox sin errores, excepto en IE.
Aquí está el js.
JAVASCRIPT Código: [ 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;
¿Por alguna razón cuando se llama a la función setColor(), resulta en un indefinido js var mundial nadie cualquier pista sobre cómo puedo solucionarlo?
La función se llama utilizando el código HTML siguiente.
[HTML]
<div>
< seleccionar onchange="setColor(value)" >
azul de <option> </option>
verde de <option> </option>
rojo de <option> </option>
gris de <option> </option>
blanco de <option> </option>
<option> limpiar </option>
</select>
< seleccionar onchange="setSize(value)" >
<option> 10 </option>
<option> 15 </option>
<option> 20 </option>
<option> 25 </option>
<option> 30 </option>
<option> 35 </option>
</select>
</div>
[/HTML MÁS EXTERNAS]
Cualquier ayuda es muy apreciada.
TIA, mayo
1 + 1 = 10 + 1 = 11 + 11 = 110
- Anonymous
- Bot


- Registrado: 25 Feb 2008
- Mensajes: ?
- Loc: Ozzuland
- Status: Online
Junio 7th, 2011, 1:24 pm
- WritingBadCode
- Graduate


- Registrado: Abr 28, 2011
- Mensajes: 214
- Loc: Sweden
- Status: Offline
No sé si esto podría tener algo que ver con ella, pero al probar el código javascript proporcionado con esto:
He observado que el "valor" o "val" como su renombrado no tiene ningún valor en IE.
He cambiado las funciones a este aspecto sólo para propósito de pruebas:
IE envió una alerta vacía mientras Chrome y FireFox enviaron el valor seleccionado.
EDITAR: malinterpretar su puesto. Veo que tenías que descubierto. Lol. Lo siento.
Aquí es algo feo mirando el código que funciona en IE y los otros (sólo para lo de color) para darle una idea:
En lugar de
Intente:
Esto supone que cambia el código HTML a esto:
Realizar 2 cambios, dándole un valor de ID y onchange no pasará ningún valor.
Código: [ 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>
He observado que el "valor" o "val" como su renombrado no tiene ningún valor en IE.
He cambiado las funciones a este aspecto sólo para propósito de pruebas:
Código: [ 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 envió una alerta vacía mientras Chrome y FireFox enviaron el valor seleccionado.
EDITAR: malinterpretar su puesto. Veo que tenías que descubierto. Lol. Lo siento.
Aquí es algo feo mirando el código que funciona en IE y los otros (sólo para lo de color) para darle una idea:
En lugar de
Código: [ Select ]
function setColor(val){ Color = val; }
Intente:
Código: [ 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);
- }
- }
- }
Esto supone que cambia el código HTML a esto:
Código: [ 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>
Realizar 2 cambios, dándole un valor de ID y onchange no pasará ningún valor.
- may
- Proficient


- Registrado: Dic 25, 2004
- Mensajes: 328
- Loc: Holland [NL]
- Status: Offline
Sí, también señaló que IE no pasar el valor como mozilla como navegador. La solución "fea" como sea
parece más bien lumbersum, pero si funciona mal que acompañan.
Estoy un poco preocupado de recorrer cada valor, que podría convertirse en un problema con grandes listas de selección y el rendimiento del cliente pobre, así que creo que mal hace el código incluso más feo por probar el tipo de navegador
Cualquier forma, si funciona...
Ah, sí antes olvidar la parte más importante...
THX para la solución sugerida
Estoy un poco preocupado de recorrer cada valor, que podría convertirse en un problema con grandes listas de selección y el rendimiento del cliente pobre, así que creo que mal hace el código incluso más feo por probar el tipo de navegador
Cualquier forma, si funciona...
Ah, sí antes olvidar la parte más importante...
THX para la solución sugerida
1 + 1 = 10 + 1 = 11 + 11 = 110
- WritingBadCode
- Graduate


- Registrado: Abr 28, 2011
- Mensajes: 214
- Loc: Sweden
- Status: Offline
Como usted dice que hay probablemente mejores formas de hacer esto, especialmente si la lista obtiene grande.
Si encuentra una mejor solución por favor no se sienten mal para compartir. =)
Una cosa menor que puede hacer si no te gusta recorrer todo es agregar un descanso;
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;
}
}
}
¿Si las choses usuario uno de los valores de la primeros a continuación, el bucle se detendrá, guardar un procesamiento? NOSE.
Si encuentra una mejor solución por favor no se sienten mal para compartir. =)
Una cosa menor que puede hacer si no te gusta recorrer todo es agregar un descanso;
Código: [ 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;
- }
- }
- }
¿Si las choses usuario uno de los valores de la primeros a continuación, el bucle se detendrá, guardar un procesamiento? NOSE.
- may
- Proficient


- Registrado: Dic 25, 2004
- Mensajes: 328
- Loc: Holland [NL]
- Status: Offline
- may
- Proficient


- Registrado: Dic 25, 2004
- Mensajes: 328
- Loc: Holland [NL]
- Status: Offline
Para cualquier persona que le gusta experimentar con esto, aquí está el código completo
TENGA EN CUENTA QUE EL AJUSTE NO (AÚN) PARA LA PRODUCCIÓN. EL CÓDIGO NECESITA REFINAMIENTO Y COMPROBACIONES DE SEGURIDAD OBVIO Y ESCAPA.
TENGA EN CUENTA QUE EL AJUSTE NO (AÚN) PARA LA PRODUCCIÓN. EL CÓDIGO NECESITA REFINAMIENTO Y COMPROBACIONES DE SEGURIDAD OBVIO Y ESCAPA.
HTML Código: [ 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 Código: [ 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


- Registrado: Abr 28, 2011
- Mensajes: 214
- Loc: Sweden
- Status: Offline
- may
- Proficient


- Registrado: Dic 25, 2004
- Mensajes: 328
- Loc: Holland [NL]
- Status: Offline
- WritingBadCode
- Graduate


- Registrado: Abr 28, 2011
- Mensajes: 214
- Loc: Sweden
- Status: Offline
may escribió:
¿LOL? ¿por qué no, invirtió parte de su tiempo en ella, aprendí un nuevo truco para que algún crédito está justificada
Dije que no era necesario ya que no aportó mucho OMI, realmente copiar código pegado de uno de mis anteriores codificaciones.
Página 1 de 1
Para responder a este tema que necesita para ingresar o registrarse. Es gratis.
Publicar Información
- Total de mensajes en este tema: 9 mensajes
- Usuarios navegando por este Foro: webspace y 125 invitados
- No puede abrir nuevos temas en este Foro
- No puede responder a temas en este Foro
- No puede editar sus mensajes en este Foro
- No puede borrar sus mensajes en este Foro
- No puede enviar adjuntos en este Foro
