Please help for my code. I must admit that I don't know what I am doing as I am just learning how to use this application and so please bear with me. I am not sure if I can do it but I created a function such as below and I hope to hear from you soon as I really need to make this work. Thanks in advance.:

function grand_total()
{ 

$PersonTotal = $_POST['$number_select'] * 50;
$TableTotal = $_POST['$number_select'] * 500;
$GrandTotal1 = ($PersonTotal + $TableTotal);
  return $GrandTotal1;

}

to post it to my textbox which has a code like below:

<label for="grandtotal">Grand Total: $</label>
    	 	<input name="GrandTotal" id="GrandTotal" type="text" maxlength="10" readonly="true" value="<?php echo grand_total($form['GrandTotal'])?>" />


		<?php helper_error('GrandTotal'); ?>

but here is the whole code for my calculation just in case you need it. My form needs a checkbox to see how many people are attending by choosing the right number using the drop down list and multiply to 50 for my first checkbox and 550 for my second checkbox then post the total as soon as it choose the number of people to my GrandTotal textbox which is read-only. I really need your suggestion and help.

<label>
        	<input name="checkbox_person" type="checkbox" value="<?php echo $checkbox_person; ?>" checked 
             />I wish to make reservations for 
    			<select name="number_select" id="number_select" onchange="calculate()">
            		<?php foreach ($number_select as $select => $prompt):?>
  					<option value ="<?php echo $select; ?>" 
  						<?php echo helper_selected($select == $form['number_select']);?>
                        onchange="<?php echo grand_total($form['GrandTotal'])?>">
  						<?php safeEcho($prompt);?>
  					</option> 

				<?php endforeach;?> 
        	</select> person(s) at $50 per person. 

		</label>
		<br />
		<label>
    	<input name="checkbox_table" class="checkbox" type="checkbox" value=<?php echo $checkbox_table; ?>
         />I wish to make reservations for 
			<select name="number_select" id="number_select" onchange="calculate()" >
				<?php foreach($number_select as $select =>$prompt) : ?>
				<option value = "<?php echo $select; ?>" 
					<?php echo helper_selected($select == $form['number_select']); ?>
                    onclick="<?php echo grand_total($form['GrandTotal'])?>" >
					<?php safeEcho($prompt); ?>
		 		</option>  
				<?php endforeach;?>
    		</select>table(s) at $500 per person. 
     		<?php helper_error('checkbox_table');?>
     	</label>
     	<br />
	 	<label for="grandtotal">Grand Total: $</label>
	 	<input name="GrandTotal" id="GrandTotal" type="text" maxlength="10" readonly="true" value="<?php echo grand_total($form['GrandTotal'])?>" />


		<?php helper_error('GrandTotal'); ?>

    read it twice, but i don't actully see what the question is.

      on the third reading .. You can't call a php function from javascript, js is client side, php is server side, looks like you should be using js for the calculation

        Hi Dagon, thanks for your time to read my post and look on my code. I'm sorry if I miss to mention my question. What I wanted to do is to call the function I created which will calculate the Total of person attending and from that will automatically post it or show to my textbox which is called "GrandTotal" such as below:
        GrandTotal: $amount

        but it doesn't call anything. I know my code is mess up and I am new to php and just started learning. Thank you and hope to hear from you soon.

          HI Dagon, thanks for you fast reply to my post. I did create a java function but still don't know how to call it. Can you please give me an idea how to do it? I guess I am lost now. Thanks.

            the only way to call GrandTotal is after you submit the form to server, if you need the value before then you have to do it with java script.

              7 days later

              Thanks Dagon for your help. I finally made it work.

                Hello. I am trying to post this to new post but somehow I can't find the button and so will try to post it here. I have a checkbox with a dropdown list to choose for a number. What I wanted to do is to set the default to 0 (zero) the selected index when they uncheck my checkbox but my function doesn't work when I tried to call it:

                function CheckDropDown(checkbox_person,number_select) {
                
                    if (!document.getElementById(checkbox_person).checked) { 
                        document.getElementById(number_select).selectedIndex = document.getElementById(number_select).options[1]; 
                    } 
                    else { 
                        document.getElementById(number_select).selectedIndex = document.getElementById(number_select).options[0]; 
                    } 
                
                } 	

                Here how I called it but it doesn't work. Please help.

                <input name="checkbox_table" class="checkbox" type="checkbox" value=<?php echo $checkbox_table; ?> onclick="$('checkbox_table').checked=false; $('numbertable_select').selectedItem = 0;" 
                			/>I wish to make reservations for 
                    			<select name="numbertable_select" id="numbertable_select" onchange="CalculateGrandTotal(this.value);" onclick="$('checkbox_table').checked=true;">
                					<?php foreach($numbertable_select as $select =>$prompt) : ?>
                  					<option value = "<?php echo $select; ?>" 
                  						<?php echo helper_selected($select == $form['numbertable_select']); ?>
                                         >
                  						<?php safeEcho($prompt); ?>
                 			 		</option>  
                <?php endforeach;?> </select>table(s) at $550 per person. <?php helper_error('checkbox_table');?>

                Any suggestions how to do it? I hope you can help me with this as soon as possible as I am running out of time. Thanks a lot.

                  Hi Dagon,

                  Thanks for the link. Somehow I am having a hard time creating a new post as I don't see the button for that. Thanks.

                    Write a Reply...