Forums

Admin OnSaveJSCode Question

augustobotossi 29 Jul, 2009
Hi!

I am trying to run the code bellow in the Admin OnSaveJSCode field. If I assign values to the variables it does work fine, so I am sure the problem is within the javascript part.

<?php
$localdb =& JFactory::getDBO();
$usuario = $row->cf_user_id;
$status = $row->Status_Pre_Reserva;
$statusF = <script type="text/javascript"> echo document.getElementById("select_34").value; </script>;
If (($status == "Concluída") and ($statusF == "Concluída")){
$localquery = "UPDATE `#__comprofiler` SET `cb_pontos` = `cb_pontos`+50 WHERE `user_id` = ".$usuario.";";
$localdb->setQuery($localquery);
$localdb->query();
}
?>

Could you guys give me some light?

Thanks!
GreyHead 30 Jul, 2009
Hi augustobotossi,

I have no idea what this line is supposed to do
$statusF = <script type="text/javascript"> echo document.getElementById("select_34").value; </script>;
PHP runs on the server and JavaScript on the browser so the two don't usually mix. I think that the only result this line will give is a PHP parse error.

Bob
augustobotossi 30 Jul, 2009
Thanks Bob for the reply.

What I am trying to do is to compare what is written in the field name "selector_34" with the related field in the table I am editing.

Is there another way to do that then?

Could you help out?

Thanks!
GreyHead 31 Jul, 2009
Hi augustobotossi,

Try
$statusF = JRequest::getVar('select_34', '', 'post);
That's the Joomla code for getting the value of a form variable.

Bob
augustobotossi 31 Jul, 2009
Thanks again Bob.

I am getting returned a NULL or blank value.

In the Admin config area, that's the code I am using in the Record Edit Template:

<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 200px;">Status da Pré-reserva</label>
<select class="cf_inputbox" id="select_34" size="1" name="Status_Pre_Reserva" >
<option value="Em aberto">Em aberto</option>
<option value="Concluída">Concluída</option>
<option value="Cancelada">Cancelada</option>
</div>

The code in the JSCODE is:
<?php
$localdb =& JFactory::getDBO();
$usuario = $row->cf_user_id;
$status = $row->Status_Pre_Reserva;
$statusF = JRequest::getVar('select_34', '', post);
If (($status == "Concluída") and ($statusF == "Concluída")){
$localquery = "UPDATE `#__comprofiler` SET `cb_pontos` = `cb_pontos`+50 WHERE `user_id` = ".$usuario.";";
$localdb->setQuery($localquery);
$localdb->query();
}
?>

Am I doing anything wrong?

Thks.

Augusto
This topic is locked and no more replies can be posted.