Javascript with PHP

The most significant difference between the two(2) languages (PHP and Java) is that Java script is client-side (meaning it runs in the web browser) and PHP is server-side.


  While PHP can not do certain things that Java script can, PHP can be used to make Java scripts


  Sending data from PHP to Java script is rather easy - as simple as creating any HTML documents.   Transfering data from Java scripts to PHP, However; is a bit more complicated.


  ex.: 


  < script type="text/javascript">


  function check_reg()

  {

   var errmsg="";

   If (document.forms[0].username.value.length == 0) {

       errmsg = 'You need to enter a value...';

   }

   if (errmsg == '') {

          return TRUE;

   } else {

       alert (errmsg);

       return FALSE;

     }

  }


  </script>


  ... . . .

  < input type="submit" name="submit" onclick="javascript: return check_reg()"/>


  To populate the text field with some initial values, enter the text you want into the field's value attribute.   For instance, many sites use the value attribute in conjunction with some JavaScript to place instructions inside text fields but then cause them to disappear as soon as the user clicks in the said field:


  example : 


  < input type="text" name="search" value="[enter words to search for]"  onfocus="javascript:if(this.value=='[enter words to search for]') 

    { this.value=''; }"/>


  This sample basic script accepts a numeric value and returns the said number, double it's value / size.   Will also print or display a set of text on screen as well.


  example : 


  < script >

  function square(i)

  {

      document.write("the call passed ",  i, "to the function.",  "< br>")

      return i * i;

  }

  </script>