Javascript And Php (window.open)
Solution 1:
This code:
<scriptlanguage="javascript">functionopen_win_editar() {
window.open ("noticiaEditarForm.php?id_noticia=<?phpecho$id; ?>", "Editar notícia", "location=1, status=1, scrollbars=1, width=800, height=455");
}
</script>
Is happening outside of the PHP while
loop, so the value of $id
will be the last value that was set to $id
in the loop. So the JavaScript code will always open the same link.
If you need the code within the PHP loop to specify the $id
value for the JavaScript, then you can pass it as an argument to the JavaScript function. Something like this:
<scriptlanguage="javascript">functionopen_win_editar(targetID) {
window.open ("noticiaEditarForm.php?id_noticia=" + targetID, "Editar notícia", "location=1, status=1, scrollbars=1, width=800, height=455");
}
</script>
So the code rendering the anchor tags in the loop would pass the argument like this:
<ahref=""onClick="open_win_editar(<?phpecho$id; ?>)">Editar</a>
The rendered output would then contain the record-specific $id
value on each a
tag to be used by the JavaScript code on the client.
Solution 2:
The id of the piece to edit is only updated within the while loop and never outside of it.
To use it as you wish you should use a parameter for the open_with_editar function:
<scriptlanguage="javascript">functionopen_win_editar(id) {
window.open ("noticiaEditarForm.php?id_noticia="+id, "Editar notícia", "location=1, status=1, scrollbars=1, width=800, height=455");
}
</script>
Now you only have to update the onclick event and hand over teh respective id:
<divclass="noticiasOpcao"><ahref=""onClick="open_win_editar(<?phpecho$id; ?>)">Editar</a>
That should work.
Regards STEFAN
Post a Comment for "Javascript And Php (window.open)"