Click here to Skip to main content
15,118,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A simple problem where a javascript function is being called by button through onclick..
And that js function calls a php function..

My actual motto is that a function should be called when a html button is that the function should be able to block a div.

Quick reply will help me alotttt

What I have tried:

function f1()
 echo "f1 called";
function f2()
 echo "f2 called";

<body background="yellow" onload="start()">
<div style="display:none" id="1">
<div style="display:none" id="2">
<div style="display:none" id="3">
<input type="button" value="welcome" onclick="one()">
<input type="button" value="welcome" onclick="two()">
function start()
function one()
function two()


Before inserting php code it worked really great i.e, onload is working and onclicking buttons corresponding functions are called.But when I put php code in it..onload is not working and onclick is also not working.It will be very helpful if someone let me know the mistake in it.
Updated 4-Apr-17 21:25pm
Peter_in_2780 5-Apr-17 0:29am
Think about it. PHP runs on the server, while the page is being built for transmission to the client.

1 solution

a very simple test for you, hope it will get you going

      function call_function (value) {
        var a = document.forms[0].a.value;
        var b = document.forms[0].b.value;
            url: 'func.php?a=' + a + '&b=' + b+"&action="+value, 
            success: function(result){
      return false;
      <FORM onsubmit='return false'>
      <INPUT NAME=a> <br>
      <INPUT NAME=b> <br>
      <INPUT TYPE=SUBMIT VALUE=add NAME=action  onclick="call_function(this.value)">
      <INPUT TYPE=SUBMIT VALUE=multiply NAME=action onclick="call_function(this.value)">
    <div id='here'>

  function add($a, $b) {
    return $a+$b;
  function multiply($a, $b) {
    return $a*$b;
  if($_GET['action'] == "add") {
    echo add($_GET['a'], $_GET['b']);
  } else if($_GET['action'] == "multiply") {
    echo multiply($_GET['a'], $_GET['b']);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900