Select help

Permalink
Hi,

I am having difficulty understanding how to add an "onchange" event to a selectbox

My code from the form:
<td><?php echo $form->select('patternID', $Obj->getPattern(),'1',array('onchange' =>'ChangeTemplateMemo()','style' => 'width: 200px')); ?></td>


And my code from the auto.js:
function ChangeTemplateMemo()
{
  var HiddenFieldToUse = eval("document.getElementById('$text_' + document.getElementById('PatternID').options[document.getElementById('PatternID').selectedIndex].value)")
  document.getElementById('ContentText').value = HiddenFieldToUse.value;
  return true;
}

What am I doing wrong? Its not going into the function at all.

View Replies:
Xenavar replied on at Permalink Reply
Bump
Xenavar replied on at Permalink Reply
bump...
Xenavar replied on at Permalink Reply
bump...
Xenavar replied on at Permalink Reply
bump
Xenavar replied on at Permalink Reply
Allright ill make the question easyer:
What is wrong with the OnChange part of this code?
<td><?php echo $form->select('patternID', $Obj->getPattern(),'1',array('onchange' =>'ChangeTemplateMemo()','style' => 'width: 200px')); ?></td>
LucasAnderson replied on at Permalink Reply
LucasAnderson
I see a spacing issue, but I'm not sure that's the problem. I don't know too much about the form helper, but I do know you could hardcode the select box if needed.

<td><?php echo $form->select('patternID', $Obj->getPattern(),'1',array('onchange' => 'ChangeTemplateMemo()','style' => 'width: 200px')); ?></td>


Also, using Firebug, you could check to see what code is actually generated on your edit/add form for the select box to see if the 'onchange' and 'style' are getting added.
tonidomenech replied on at Permalink Reply
tonidomenech
PRIMERO

Mira si en el controller.php tienes definidas las llamadas al los paquetes jquery.

Recuerda que el mejor lugar es en:

public function on_page_view() {
  $html = Loader::helper('html');
  $this->addHeaderItem($html->css('jquery.ui.css'));
  $this->addHeaderItem($html->css('ccm.dialog.css'));
  $this->addHeaderItem($html->javascript('jquery.ui.js'));
  $this->addHeaderItem($html->javascript('ccm.dialog.js'));
}



Luego puedes intentar poner el javascrip dentro de las etiquetas <script type="text/javascript"></script>

en el mismo php o mirar que la rutas a tu js son conrrectas.

Por el resto no veo nada anómalo.

Espero haber podido ayudar
tonidomenech replied on at Permalink Reply
tonidomenech
your problem is one error in sintaxis.

The correct sintaxis is:
<?php echo $form->select('cEst'.$i,$EstadoG,$cEstado,array("onchange"=>"mifuncion('".$cNumVenta."','".$i."')"),array('style'=>'width:100px')); ?>
tonidomenech replied on at Permalink Reply
tonidomenech
in your subject:

<td> <?php  echo  $form -> select ( 'patternID' ,  $Obj -> getPattern ( ) , '1' , array ( 'onchange'  => "'ChangeTemplateMemo()'" , 'style'  =>  'width: 200px ' ) ) ;  ?> </ td>
INTcommunications replied on at Permalink Reply
INTcommunications
I am still trying to figure out how to get the array fom a db into the select - Can't find any samples of this - I noticed that you have the $Obj->getPattern() which I am guessing is a function in your controller?

What is the intention of putting the value in a hidden textbox? I see that you have 1 as your selected default. Wouldn't there be some other kind of look-up function to see what was previously selected?



<td><?php echo $form->select('patternID', $Obj->getPattern(),'1',array('onchange' =>'ChangeTemplateMemo()','style' => 'width: 200px')); ?></td>


Can't figure this out - just need someone to post working example somewhere.
tonidomenech replied on at Permalink Reply
tonidomenech
de dejo un codigo que funciona correctamente:

COGER LOS DATOS DE LA BASE DE DATOS CON UNA CONSULTA:

<?php
$db = Loader::db();
$consulta="SELECT * FROM TABLA ORDER BY `COLUMNA`.`id` ASC";
$data = $db->Execute($consulta);
foreach($data as $row){
         $datosselect[] = $row[datosparaselect];
         $datos[0]= $datosselect;         
}
?>


<h2>PARA PASAR LOS DATOS AL SELECT:</h2>

<?php echo $form->select('idselect', $datos[0], $datosselected, array('style'=>'width:150px;'));


[/code]