Client and Server Side Scripting
Client and Server Side Scripting
<body>
<p>Click the following button to see the result: </p>
<form>
<input type = "button" value = "Click Me" onclick = "getConfirmation();" />
</form>
</body>
</html>
Prompt Box
: A prompt box is often used if you
want the user to input a value before
entering a page. When a prompt box
pops up, the user will have to click
either “OK’ or “cancel” to proceed after
entering an input value. If the user
clicks “OK” the box returns the input
value. If the user clicks “cancel” the
box returns null. Syntax: prompt
(“sometext”, “defaultvalue”);
<html>
<script language="javascript" type="text/javascript" >
function welcomeMsg(promptMsg)
{
visitorName = prompt(promptMsg, '');
alert("Welcome " + visitorName + "," + "\n\n" + "You
are currently listening to one of the best web developers
of all time , Asher ! Hope you find Asher useful!" + "\n\n"
+ "Hey " + visitorName + ", don't forget to introduce me
to your friends!");
}
</script>
<form>
<input type="button" onclick="welcomeMsg('What is your
name?');" value="Read our Welcome Message!" />
</form>
</html>
JavaScript functions A function contains a
code that will be executed by an event or
by a call to the function. We may call a
function from anywhere within a page
Syntax :- Function function name(var1,
var2…varx) {Some code}
JavaScript events Events are the beating
heart of any JavaScript application. This
gives us an overview of what event
handling is , what its problems are and
how to write proper cross-browser scripts
Without events there are no scripts.
Whenever a user of JavaScript takes
action, he causes an event.
A common scripting language for server
scripting is “PHP”
Uses of PHP:
?php
if( $_POST["name"] || $_POST["age"] )
{
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action="<?php $_PHP_SELF ?>" method="POST">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
PHP variables All variables in PHP
are denoted with a leading dollar
sign “$”. The value of variable is
the value of its most recent
assignment. PHP does a good job
of automatically converting types
from one to another when
necessary. Variables in PHP do not
have intrinsic types. (a variable
does not know in advance whether
it will be used to store a number or
a string of characters.)
Data types in PHP
INTEGERS: are whole numbers, without a decimal
point, like “574”.
DOUBLES: are floating point numbers, like
“3.146”.
BOOLEANS: have only two possible values either
“true” or “false”.
NULL: null is a special type that only has one
value i.e. “null”.
STRINGS: are sequences of characters like “hello
friends”
Arrays: arrays are names and indexed collection
of other values.
PHP control structures
if…..else statement :
Use this statement if you want to
execute some code if a condition is
true and another code if a condition is
false. Example:
if (condition)
switch(expression)
{
case label 1
Code to be executed if expression=label 1;
break;
case label 2
Code to be executed if expression= label 2;
Break;
default:
code to be executed if expression is different
from both label 1 and label 2;