php - symfony 1.4 and jquery. How to pass variable to jquery function? -
i have template indexsuccess.php ajax function:
<script type="text/javascript"> jquery(document).ready(function(){ jquery('#test<?php $mensajes->getidmensajes() ?>').click(function(){ jquery('#contenido<?php $mensajes->getidmensajes() ?>').load(this.href); return false; }); }); </script> <h2>listado de mensajes emitidos</h2> <h3>en orden cronológico inverso (más nuevo primero)</h3> <table id="enviados" width="60%" border="1" cellpadding="8"> <thead> <tr> <th>fecha creación</th> <th>contenido del mensaje</th> <th>destinatarios</th> </tr> </thead> <tbody> <?php foreach ($mensajess $mensajes): ?> <tr> <td width="10%" align="center"> <?php echo date('d/m/y', strtotime($mensajes->getfechaalta())) ?></td> <td bgcolor="<?php echo $mensajes->getcolores()->getcodigo() ?>"><?php echo $mensajes->getcuerpo() ?></td> <td width="20%" id="contenido<?php echo $mensajes->getidmensajes() ?>"> <a id="test<?php echo $mensajes->getidmensajes() ?>" href="<?php echo url_for('mensajes/receptores?idmensajes='.$mensajes->getidmensajes()) ?>">ver receptores</a> </td> </tr> <?php endforeach; ?> </tbody> </table> i want pass value $ message-> getidmensajes () ajax function. have different id each row, not work. function works when set value. example: jquery ('# test24') , jquery ('# contenido24') works value idmensajes=24 . how pass value $ message-> getidmensajes () ajax function?
your question not clear wrote
jquery ('#contenido24') works value idmensajes=24 also, have this
jquery('#test<?php $mensajes->getidmensajes() ?>').click(function(){ jquery('#contenido<?php $mensajes->getidmensajes() ?>').load(this.href); return false; }); so, think have elements similar ids, such contenido24, contenido25 , on data container , links ids #test24, #test25 so. if case can use
jquery(document).ready(function(){ // register click handler tags id begins 'test' jquery("a[id^='test']").click(function(e){ e.preventdefault(); // instead of return false jquery('#contenido'+this.id.match(/\d+/)[0]).load(this.href); }); }); jquery('contenido'+this.id.match(/\d+/)[0]) select elements id #contenido24, contenido25 depending on id of a, if a tag has id='test20' it'll select #contenido20 , load content ajax call element.
Comments
Post a Comment