Jump to content

<option selected attribute problem newbie help needed pls [RESOLVED]


helloise

Recommended Posts

i have the following code: $catcher_names = LpmCatcherPeer::getByAllNames(); foreach($catcher_names as $row) { ?> <option value="<?php echo $row->getName()."/".$row->getId();?>" selected="<?php echo $catcher_name; ?>"><?php echo $row->getName();?></option> <?php }a service is connected to a catcher..so when i select a service the corresponding catcher must show in the dropdown list but it is not...the selected attribute part is not working and i have tested that $catcher_name does contain the correct name for the service i selected please help???thanks

Link to comment
Share on other sites

but it's in a foreach loop, so every option is going to be selected, which doesn't make sense. You could set one of them to selected as a default for when the list renders.If you need to change something else based on the selection a user makes in the dropdown, you would probably want to use javascript and add an onchange event handler to the select tag to run a function, which could be written to do something based on the item just selected.

Link to comment
Share on other sites

but it's in a foreach loop, so every option is going to be selected, which doesn't make sense. You could set one of them to selected as a default for when the list renders.If you need to change something else based on the selection a user makes in the dropdown, you would probably want to use javascript and add an onchange event handler to the select tag to run a function, which could be written to do something based on the item just selected.
ooo yes quite right so how do i set the default then please????? can you show me please???the onchange i with javascript i know now thanksthanks
Link to comment
Share on other sites

ooo yes quite right so how do i set the default then please????? can you show me please???
Can you show us more code? Then we can try to help you work it out.I am not sure what you mean here:
a service is connected to a catcher..so when i select a service the corresponding catcher must show in the dropdown list but it is not...the selected attribute part is not working and i have tested that $catcher_name does contain the correct name for the service i selected
Do you have two drop downs? One for service one for catcher? Or am I missing something? Like I said can you provide a little bit more code so we can get an idea of the context.Also, the only value that can go in the selected attribute is "selected" and nothing else. You can't put names or values of elements in there.<option value='aVal' selected='selected'>...</option> <----- This is the only way you can write the selected attribute
Link to comment
Share on other sites

here is all my code for _form.php:<?php use_stylesheets_for_form($form) ?><?php use_javascripts_for_form($form) ?><html><head><script type="text/JavaScript"> function refreshPage(value) { //must check here if user selected another value from the dropdown and if it is "zed-catcher" display something window.location.reload(); } </script></head></html> <body> <form action="<?php echo url_for('adminservice/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>><?php if (!$form->getObject()->isNew()): ?><input type="hidden" name="sf_method" value="put" /><?php endif; ?><table > <tfoot> <tr> <td colspan="2"> <?php echo $form->renderHiddenFields(false) ?>  <a href="<?php echo url_for('adminservice/index') ?>">Back to list</a> <?php if (!$form->getObject()->isNew()): ?>  <?php echo link_to('Delete', 'adminservice/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?> <?php endif; ?> <input type="submit" value="Save" /> </td> </tr> </tfoot> <tbody> <?php echo $form->renderGlobalErrors() ?> <tr> <th><?php echo $form['name']->renderLabel() ?></th> <td> <?php echo $form['name']->renderError() ?> <?php echo $form['name']?> </td> </tr> <tr> <th><?php echo $form['logo_url']->renderLabel() ?></th> <td> <?php echo $form['logo_url']->renderError() ?> <?php echo $form['logo_url'] ?> </td> </tr> <tr> <th><?php echo $form['wap_home']->renderLabel() ?></th> <td> <?php echo $form['wap_home']->renderError() ?> <?php echo $form['wap_home'] ?> </td> </tr> <tr> <th><?php echo $form['call_center_number']->renderLabel() ?></th> <td> <?php echo $form['call_center_number']->renderError() ?> <?php echo $form['call_center_number'] ?> </td> </tr> <tr> <th><?php echo $form['catcher_id']->renderLabel(); $catcher_id = $form->getObject()->getCatcherId(); $catcher = LpmCatcherPeer::getByCatcherId($catcher_id); $catcher_name = $catcher->getName(); ?></th> <td> <?php echo $form['catcher_id']->renderError() ?> <select name="services"> <?php $catcher_names = LpmCatcherPeer::getByAllNames(); foreach($catcher_names as $row) { ?> <option value="<?php echo $row->getName()."/".$row->getId();?>" selected="" onchange="refreshPage(this.value)"><?php echo $row->getName();?></option> //on the preceding form is a list of services(each service is connected to a catcher). the user will click on a service and this form will then show..on this form is a dropdown list of catchers...the catcher connected to the service selected on the previous form must be the highlighted/selected/default one showing up on the dropdown <?php } ?> </select> </td> </tr> <tr> <th><?php echo $form['price_description']->renderLabel() ?></th> <td> <?php echo $form['price_description']->renderError() ?> <?php echo $form['price_description'] ?> </td> </tr> <tr> <th><?php echo $form['invalid_msisdn_text']->renderLabel() ?></th> <td> <?php echo $form['invalid_msisdn_text']->renderError() ?> <?php echo $form['invalid_msisdn_text'] ?> </td> </tr> <tr> <th><?php echo $form['terms_and_conditions']->renderLabel() ?></th> <td> <?php echo $form['terms_and_conditions']->renderError() ?> <?php echo $form['terms_and_conditions'] ?> </td> </tr> </tbody> </table></form></body>hope this makes more sense :)thanks

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...