javascript.php

<?
 function javascript($message , $variable , $action , $text , $varName){
 /*
  Function that can display different types of javascript events
  $message : the message to print (string)
  $variable : boolean (True, False ;) that indicates if $message is the text to print
  or the name of a javascript variable
  $action : indicate what event should happen (string with those possible values :
  alert, prompt, confirm, status
  $text : optional parameter used if $action == prompt, in that case :
  $message is the default value of the text field propoesd by the prompt
action, and
  $text is the question to display
  $varName : optional parameter used if $action == prompt, in that case :
  $varName is the name of the value where the content of the text field is
stored
  Hope that helps ;)
  */
  $script = "<script language=javascript>";
 
  if (strcmp ($action, "alert") == 0)
  if ($variable)
  $script .= "window.alert (".$message.")";
  else
  $script .= "window.alert ('".$message."')";
  if (strcmp ($action, "confirm") == 0)
  if ($variable)
  $script .= "window.confirm (".$message.")";
  else
  $script .= "window.confirm ('".$message."')";
 
  if (strcmp ($action, "prompt") == 0)
  if ($variable)
  $script .= "var ".$varName."= window.prompt ('".$text."', ".$message.")";
  else
  $script .= "var ".$varName."= window.prompt ('".$text."', '".$message."')";
 
  if (strcmp ($action, "status") == 0)
  if ($variable)
  echo "<script language=javascript>window.status =
".$message."</script>";
  else
  echo "<script language=javascript>window.status =
'".$message."'</script>";
 
  $script .= "</script>\n";
  echo $script;
 
 // // Usage example
 // javascript ("Valeur par defaut de prompt", True, "prompt", "Saisissez une valeur", "nomVariableResultat");
 // // La ligne precedente a normalement cree une erreur car il n'existe pas de variable javascript nommee "Valeur par defaut de prompt"
 // javascript ("Valeur par defaut de prompt", False, "prompt", "Saisissez une valeur", "nomVariableResultat");
 // javascript ("nomVariableResultat", True, "alert");
 // javascript ("nomVariableResultat", True, "confirm");
 // javascript ("nomVariableResultat", True, "status");
}
echo javascript("Valeur par defaut de prompt", False, "prompt", "Saisissez une valeur", "result");
echo $result;
?>
 
info/javascript.txt · Dernière modification: 2008/11/29 08:57 (modification externe)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki