Forum Moderators: open

Message Too Old, No Replies

document.form.name.value is undefined

         

eduardor2k

9:07 am on Feb 18, 2009 (gmt 0)

10+ Year Member



Hi to everyone, i'm new & i'm having trouble with the following code:

<script language="javascript" type="text/javascript">
<!--
function editar(comentario) {
location.replace("?seccion=EditarComent&comentario=" + comentario);
}
function borrar(comentario) {
var respuesta = confirm("¿Seguro que quieres eliminar este comentario?")
if(respuesta){
location.replace("?seccion=BorrarComent&comentario=" + comentario);
}
}
function bloquear(comentario) {
var respuesta = confirm("¿Seguro que quieres bloquear a este usuario?")
if(respuesta){
location.replace("?seccion=BloqComent&comentario=" + comentario);
}
}
-->
</script>

<form name="formulario" enctype="multipart/form-data">
<h2>Acceso Rápido</h2>
<p>Si conoces el #ID del comentario que quieres borrar, editar o bloquear al usuario
que lo ha escrito, solo tienes que escribir a continuación el ID y seleccionar
la opción deseada.</p>

<table style="border-width: 0; width: 100%">
<tr>
<td><b>ID del Comentario: <input type="text" name="comentario" />&nbsp;
<input type="button" value="Borrar" OnClick="javascript: borrar(document.formulario.comentario.value); return false;">&nbsp;
<input type="button" value="Bloquear" OnClick="javascript: bloquear(document.formulario.comentario.value); return false;">&nbsp;
<input type="button" value="Editar" OnClick="javascript: editar(document.formulario.comentario.value); return false;">
</td>
</tr>
</table>
</form>

I get the following error in firebug:

document.formulario.comentario is undefined
[Break on this error] editar(document.formulario.comentario.value);

Thanks for helping.

rocknbil

3:36 pm on Feb 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard eduardor2k, seems to run fine here, although I did get the following validation errors:

Nesting error: "<b>" should be close before closing table

... but it ran OK even with that in place. I also got "ASCII values greater than 127 found, use (appropriate entity) instead" but that might just be from the copy/paste. (Rápido, continuación ...)

Did you try running just this code on the page as you have it here? It may be some other element on the page mucking up the code. If invalid code causes a form to close prematurely, the browser won't recognize the form and won't run JS . . .

EDIT:

You can remove the comments entirely, or just fix the last one . . .

-->
</script>

Like so

//-->
</script>

since the closing comment is within the Javascript, normally this will cause an error because --> is not valid Javascript. Seems later browsers are forgiving of this . . . perhaps yours is not.

eduardor2k

12:03 am on Feb 19, 2009 (gmt 0)

10+ Year Member



Thanks Rocknbil for answering, at the end my code worked fine, the problem was that in the same page I copy/pasted the form code, and i had to forms with the same name, making my script to not work.

Thank you so much, because your answer made me, see that error.