Foros del Web » Programando para Internet » Javascript »

cambio de imagen con src

Estas en el tema de cambio de imagen con src en el foro de Javascript en Foros del Web. tengo una funcion en javascript que me funciona perfectamente en explorer 6 pero en 7 no me hace el cambio de una imagen con la ...
  #1 (permalink)  
Antiguo 10/06/2009, 16:14
Avatar de Fabu_dina  
Fecha de Ingreso: enero-2004
Mensajes: 425
Antigüedad: 20 años, 3 meses
Puntos: 1
cambio de imagen con src

tengo una funcion en javascript que me funciona perfectamente en explorer 6 pero en 7 no me hace el cambio de una imagen con la siguiente instruccion alguien
sabe como lo puedo solucionar.


Código:
var img_obj = new Image();
    img_obj = form.file1.value;
    document.changing.src = img_obj;

donde no me funciona es cuando deberia de hacer el cambio del elemento changing con la propiedad src

Saludos y muchas gracias
  #2 (permalink)  
Antiguo 11/06/2009, 02:01
Avatar de KiraSakuya  
Fecha de Ingreso: junio-2009
Mensajes: 67
Antigüedad: 14 años, 11 meses
Puntos: 1
Respuesta: cambio de imagen con src

Intentalo con getElementById, suponiendo que el id es changing...

document.getElementById("changing").src= img.obj;

Espero que te sirva :)
  #3 (permalink)  
Antiguo 11/06/2009, 02:20
Avatar de Fabu_dina  
Fecha de Ingreso: enero-2004
Mensajes: 425
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: cambio de imagen con src

Nop sigue sin funcionar
  #4 (permalink)  
Antiguo 11/06/2009, 03:06
Avatar de KiraSakuya  
Fecha de Ingreso: junio-2009
Mensajes: 67
Antigüedad: 14 años, 11 meses
Puntos: 1
Respuesta: cambio de imagen con src

mmm, aplicalo tambien al elemento de la pagina file1, de todas formas cuando trabaje yo con un elemento de tipo file, no definia ningun objeto de tipo imagen, ya que lo que vas a usar para el src es una cadena, prueba:

document.getElementById("changing").src = document.getElementById("file1").value;
(Estoy suponiendo que changing y file1 son Id de los elementos correspondientes)

Una cosa que suelo decir cuando no tengo el codigo delante, fijate bien en todas la variables, sobre todo en las mayusculas, que muchas veces se fallan por tonterias como esa.

A ver si avanzamos ;)
  #5 (permalink)  
Antiguo 11/06/2009, 03:08
Avatar de Fabu_dina  
Fecha de Ingreso: enero-2004
Mensajes: 425
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: cambio de imagen con src

lo que pasa es que si me funciona perfectamente en explorer seis pero en el siete ya no y por supuesto que en ocho menos
  #6 (permalink)  
Antiguo 11/06/2009, 03:30
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: cambio de imagen con src

Hola Fabu_dina

Me parece que tienes puesto un name a la imagen, en lugar de un id como te está diciendo KiraSakuya

Si pones el código será más fácil ayudarte.

Saludos,
  #7 (permalink)  
Antiguo 11/06/2009, 03:36
Avatar de Fabu_dina  
Fecha de Ingreso: enero-2004
Mensajes: 425
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: cambio de imagen con src

Código:
<%@LANGUAGE="VBSCRIPT"%>
<%response.buffer=true
Func = Request("Func")
if isempty(Func) Then
Func = 1
End if
Select Case Func
Case 1
%><TITLE>Subir Imagenes</TITLE>
<META HTTP-EQUIV="The JavaScript Source" CONTENT = "no-cache">
<style>
 .divstyle{
	position:absolute;
width="0";	height:"0";
	width: 24px;
}
body {
	background-color: #CCCCCC;
}
</style>

<SCRIPT LANGUAGE="JavaScript">

function showimg(form)
{
adres = form.file1.value;
index = adres.indexOf(".gif");
index = index + adres.indexOf(".pdf");
index = index + adres.indexOf(".jpg");
if (form.file1.value == "")
  {alert("No se encuentra el archivo!");}
else
  {if (index == -3){alert("Unknow image type");
    form.width.value=0;
    form.height.value=0;}
  else
    {
    var img_obj = new Image();
    img_obj = form.file1.value;
    document.changing.src = img_obj;
    document.changing2.src= img_obj;
    document.changing.width = 273;
    document.changing.height = 170;

	
valor = img_obj;
archivo = valor.split("\\");
nArchivo = archivo[archivo.length-1];


    window.opener.colores.foto.value=form.file1.value;
    window.opener.colores.foto.value=nArchivo;
    window.opener.form1.changing.src= img_obj;
    window.opener.form1.changing2.src= img_obj;
    set();
}
  }
}

</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../admin/include/style.css" rel="stylesheet" type="text/css">
</HEAD>

<BODY vlink=#0000ff onLoad="set()">

<tr><td width="99%" align=center>

<basefont size=3>
<center>
<form ENCTYPE="multipart/form-data" ACTION="imagen.asp?func=2" METHOD=POST id=form1 name=form1>
<input name="file1" type="file" id="file1" onChange="showimg(this.form)">

<table width="290" height="180" border="1" cellpadding="0" cellspacing="0" bordercolor="#000066" bgcolor="#FFFFFF">
  <tr>
    <td><table width="273" height="104" border ="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFFF">
      <tr>
        <td><div align="center"><img src="../icons/lphoto.png" name="changing" width="32" height="32" align="absmiddle"> </div></td>
      </tr>
    </table></td>
  </tr>
</table>
<INPUT type="submit" value="Subir">
</form>
<div STYLE="left:732px;top:191px" class="divstyle">
<P ><img src="/2009/images/icons/lphoto.png" name="changing2" width="32" height="32"></p>
</div>
</center>
<a name="source">


<%
Case 2
ForWriting = 2
adLongVarChar = 201
lngNumberUploaded = 0

'Get binary data from form 
noBytes = Request.TotalBytes 
binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
Set RST = CreateObject("ADODB.Recordset")
LenBinary = LenB(binData)

if LenBinary > 0 Then
RST.Fields.Append "myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("myBinary")
End if
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8 
strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
Do While lngCurrentEnd > 0
strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
strDataWhole = replace(strDataWhole,strData,"")

lngBeginFileName = instr(1,strdata,"filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34)) 
if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then

Response.Write "<H2> Ha ocurrido el siguiente error.</H2>"
Response.Write "Debes elegir un archivo para subir"
Response.Write "<BR><BR>Pulsa el botón volver, realiza la corrección."
Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Volver' id='button'1 name='button'1>"
Response.End 
End if
if lngBeginFileName <> lngEndFileName Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)

tmpLng = instr(1,strFilename,"\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"\")
Loop

FileName = right(strFilename,len(strFileName) - PrevPos)

lngCT = instr(1,strData,"Content-Type:")

if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
Else
lngBeginPos = lngEndFileName
End if
lngEndPos = len(strData) 

lngDataLenth = lngEndPos - lngBeginPos
strFileData = mid(strData,lngBeginPos,lngDataLenth)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(server.mappath("..") & "\muebles\" &_
 FileName, ForWriting, True)
f.Write strFileData
Set f = nothing
Set fso = nothing

lngNumberUploaded = lngNumberUploaded + 1

End if

lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
loop


%>
<SCRIPT>
	window.close();
</script>
<%
End Select 
%>

</body></html>
  #8 (permalink)  
Antiguo 11/06/2009, 03:38
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: cambio de imagen con src

Cita:
Iniciado por JavierB Ver Mensaje
Me parece que tienes puesto un name a la imagen, en lugar de un id como te está diciendo KiraSakuya
Código:
<img src="http://www.forosdelweb.com/f13/icons/lphoto.png" name="changing" width="32" height="32" align="absmiddle">
Saludos,
  #9 (permalink)  
Antiguo 11/06/2009, 04:06
Avatar de KiraSakuya  
Fecha de Ingreso: junio-2009
Mensajes: 67
Antigüedad: 14 años, 11 meses
Puntos: 1
Respuesta: cambio de imagen con src

Justo :) a ver si poniendoles id se te soluciona el problema :D

(PD: JavierB para futuros encuentros mejor Kira :) Lo de sakuya es porque ya estaba cogido U_U)
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:42.