How to call a Javascript function using Cakephp -



How to call a Javascript function using Cakephp -

i have function in view(aval_comp.ctp). when calculation in function on controller, want phone call javascript function.

js function:

<script type="text/javascript"> function calculatetotal(){ var total = document.getelementbyid('valor1').innerhtml*1 + document.getelementbyid('valor2').innerhtml*1 + document.getelementbyid('valor3').innerhtml*1 + document.getelementbyid('valor4').innerhtml*1 + document.getelementbyid('valor5').innerhtml*1 + document.getelementbyid('valor6').innerhtml*1; document.getelementbyid('total').innerhtml = total; } </script>

how phone call function in controller?

well talelcool not quite right.

you can phone call javascript functions php highly discouraged , not how should utilize functions. php server, js client, never mix two!

anyway, if in php echo out this:

<?php echo "<script>calculatetotal()</script>"; ?>

that should work. it's not perfect if set @ end of .php page should phone call it.

the reason might not work may seek phone call function before browser has had time define it. if having problem allow me know :)

but

as stated, should on server. if want utilize values on screen have been input, can utilize ajax. suggest learning jquery this, help in alot of other areas well.

javascript function cakephp

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -