Jump to content

refresh page with newley selected value from dropdown help needed pls


helloise

Recommended Posts

from what i know i have to refresh the page with the newley selected value and the check it:f...and how to go about this i need to use AJAX and or javascript :) i am reading up on it cos i am newbie at all of this...anybody to help me start on this/point me in the right direction/ explain what needs to be done please??? i dont know where to begin :)my code so far: <?php echo $form['catcher_id']; //gives the dropdown $catcher_names = explode(" ",$form['catcher_id']); foreach($catcher_names as $val) { //echo $val; if ($val == "zed-catcher") //not doing the if cos page has not been refreshed with new value { echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; } } ?>many thanks!

Link to comment
Share on other sites

thank you i sorted it but now the next problem is my php with in the javascript is now not working :)<script type="text/JavaScript"> function refreshPage(s) { window.location.reload(); if((s.options[s.selectedIndex].value) = "zed=catcher") { alert (s.selectedIndex); //this is showing <?PHP //the next lines aint executed echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; ?> } } </script>what am i doing wrong?thanks

Link to comment
Share on other sites

you can't run PHP code within Javascript code like that. If you are trying to execute PHP code through the client (i.e. a Javascript function at run time), you have to do it using AJAX. The concept that you need to understand is that PHP only executes on the server side, and sends the output to the client, which is the sole domain of Javascript. The two cannot interact with each other unless you use something like AJAX. With AJAX, you could pass the value of s.selectedIndex to a PHP script which could return to you data that you can use to alter the state of your HTML document.

Link to comment
Share on other sites

thanks very much..i have taken out the code and have it plan and simple like this now:<html><head><script type="text/JavaScript"> function refreshPage(s) { window.location.reload(); if((s.options[s.selectedIndex].value) = "zed-catcher") { var $index = s.selectedIndex; var $value = s.options[$index].value; alert (s.selectedIndex); alert ($value); window.location.reload(); return $value; } } </script></head></html>the problem now is: the alerts show the correct values but as soon as i close the second alert, the dropdown goes back to the ORIGINAL value and NOT the newly selected?????1. how do i let it stay on the newly selected value2. i have a return there but have no idea on how to use it or what to do with it..i put it there so someone can show me how a return works please???my whole form.php code:<?php use_stylesheets_for_form($form) ?><?php use_javascripts_for_form($form) ?><html><head><script type="text/JavaScript"> function refreshPage(s) { window.location.reload(); if((s.options[s.selectedIndex].value) = "zed-catcher") { var $index = s.selectedIndex; var $value = s.options[$index].value; alert (s.selectedIndex); alert ($value); window.location.reload(); return &value; //where does it return to ???? how/what to do with a return value??? } } </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['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" onchange="refreshPage(this.form.services)"> <?php $catcher_names = LpmCatcherPeer::getByAllNames(); foreach($catcher_names as $row) { ?> <option value="<?php echo $row->getName()."/".$row->getId();?>" <?php if($row->getName() == $catcher_name) echo ' selected="selected"'; ?> ><?php echo $row->getName();?></option> <?php } if ($row->getName() == "zed-catcher") //just thought with the return in my java script i can pass the newley selected value back to here and if it meets the if i echo these lines?? { echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; } ?> </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> </tbody> </table></form></body>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...