JavaScript parameter pass

0

I try to make a function in JavaScript that receives two parameters, it works perfectly with a single argument but when I try to pass 2 it stops working and I do not find the fault any idea?

This is how I call the function

    out.print("<a href='#'  onclick='confirmDelete('"+id+"','"+ext+"');'>Eliminar</a>");//Opción a eliminar

Javascript function

<script type="text/javascript">
function confirmDelete(idCat,ext) {

var id=idCat;
var extencion=ext;
if(confirm("¿Desea eliminar la categoria?"+id+extencion)) {

//document.location.href= '../EliminarCategoria?idCat='+id+'';

}

} 
</script>
    
asked by Missael Armenta 04.07.2016 в 21:54
source

1 answer

1

The problem is that you are using single quote ' in both the onclick attribute and the parameters.

It should be formatted one with double quote and the other with single quote.

out.print("<a href='#' onclick=\"confirmDelete('"+id+"','"+ext+"');\">Eliminar</a>");
             //                 ^ .. aqui y . ........... ... aqui  ^

As you can see, you must escape the double quote so that java knows that it is part of the string and not the end of it. That is% "... onclick=\" ... \" ... " .

    
answered by 04.07.2016 / 22:18
source