如何在发布页面之前获取所选下拉列表的值

<?php 

$options = array(
                  500  => 500,
                  1000 => 1000,
                  2500 => 2500,
                  5000 => 5000,
                );

echo form_dropdown('units',$options);

?>

$db_num = 25; # a random number
$post_num = $set_num * (units-selected) 

how do i get multiply the selected value of of the units dropdown with my $db_num when submit is clicked? I think this may need javascript but is it possible without?

On my controller I tried this:

$db_num = $this->input->post('db_num');
$units = $this->input->post('units');

$answer = $db_num * $units;

...

echo $answer; 

(result is no error and no insert. What am I doing wrong?)

The database field that was passing my variable needed to be set to INT - Problem solved.

something like :

<form ... onsubmit="return functionwhereyouwilldothemath(this)" >
</form>

<script type="text/javascript">
function functionwhereyouwilldothemath(el) { //el = javascript form object
    var db_num = <?=$db_num?>; //yup this is legit.
     //do your math
    return true; //will cause the page to reload uppon submit.
}
</script>

use php implode function to store and explode function to display

$itm= $_POST['hospital_department']; $comma_separated = implode("-", $itm);

$data['hospital_department']            = $comma_separated;