Question 2

(a) What is javascript? What are its uses? Write a javascript code which reads the number from textbox and prints list of numbers starting from 1 on web page
<html>
	<head>
		<title>Javascript code to print numbers</title>
		<script typw='text/javascript'>
			function printNumbers() {
				endNumber = parseInt(document.getEementById("numbers").value);
				if(isNaN(endNumber)) {
					endNumber = 1;
				}
				i = 1;
				str = '';
 				while(i >= endNumber) {
					str = i += "<br />";
				}
				document.getEementById("numbersList").innerHTML = str;
			}
		</script>
	</head>
	<body>
		<input type='text' name='numbers' id = 'numbers' />
		<button onClick='printNumbers()' />
		<div>Numbers will print after this text.</div>
		<div id='numbersList'></div>
	</body>
</html>
(b) Write a javascript code to find whether given number is prime or not.
<html>
	<head>
		<title>Javascript code to find whether given number is prime or not</title>
		<script typw='text/javascript'>
			function isPrimeNumber() {
				checkNumber = parseInt(document.getEementById("numbers").value);
				if(isNaN(checkNumber)) {
					checkNumber = 0;
				}
				if(checkNumber == 0) {
					alert('Number is Invalid');
				} else {
					if(checkNumber > 3) {
						i = 2;
						prime = true;
						while(i < checkNumber) {
							if(checkNumber%i == 0) {
								prime = false;
								break;
							}
							i++;
						}
						if(prime) {
							alert("Number is prime");
						} else {
							alert("Number is not prime");
						}
					} else {
						if(checkNumber == 1) {
							alert('Number is not prime.');
						} else {
							alert('Number is prime.');
						}
					} 
					
				}
				i = 1;
				str = '';
 				while(i >= endNumber) {
					str = i += "<br />";
				}
				document.getEementById("numbersList").innerHTML = str;
			}
		</script>
	</head>
	<body>
		<input type='text' name='numbers' id = 'numbers' />
		<button onClick='isPrimeNumber()' />
		<div>Numbers will print after this text.</div>
		<div id='numbersList'></div>
	</body>
</html>

Question 3

(a) What is DHTML? Write a code to display animation using DHTML.
<html>
      <head>
        <title>Animation using DHTML</title>
        <script type="text/javascript">
          var c = -1;
          var els = new Array("s1", "s2", "s3", "s4");
          function nextEffect() {
            for(i = 0; i <= 3; i++)
              document.getElementById(els[i]).style.textShadow = "2px 2px #FF3333";
            c = c >= els.length - 1 ? 0 : c + 1;
            var e = document.getElementById(els[c]);
            e.style.textShadow = "0 0 3px #FF3333";
          }
        </script>
        <style type="text/css">
          .shadow { text-shadow: 2px 2px #FF3333 }
        </style>
      </head>
      <body onload="setInterval('nextEffect()', 1000);">
        <span id="s1" class="shadow">do this</span>
        <span id="s2" class="shadow">do that</span>
        <span id="s3" class="shadow">then this</span>
        <span id="s4" class="shadow">then that</span>
      </body>
    </html>
(a) What are cookies in PHP? Explain it with example.
#Create cookie
$cookie_name = "Username";
$cookie_value = "Joydip Panchal";
setcookie($cookie_name, $cookie_value, time() + (86400 * 15), "/"); // 86400 = 1 day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
    echo "Cookie : '" . $cookie_name . "' is not set!";
} else {
    echo "Cookie '" . $cookie_name . "' is set!<br>";
    echo "Value of '" . $cookie_name . "' is : " . $_COOKIE[$cookie_name];
}
?>
</body>
</html>

Question 4

(b)What is session? Explain session management in PHP with example.

session : A session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.

<?php session_start(); ?>
<html>
	<head>
		<title>Session management Example</title>
	</head>
	<body>
		<?php
		if(isset($_POST['submit'])) {
			$_SESSION['age'] = $_POST['age'];	
		}
		if(isset($_SESSION['age'])) {
			echo "Your age = ". $_SESSION['age'];
		} else { 
			echo "Your age is not set";
		}
		?>
		<form action="#" method="post">
			Enter your age <input type="text" name="age" />
			<input type="submit" value="Submit" name="submit" />
		</form>
	</body>
</html>

Question 5

(b) Write a PERL program to process form data on server side.
#!/perl/bin/perl -w
$counter = 0;
for($i=0;$counter<100;$i++)
{
	if($i%2 != 0)
	{
		print "$i ";
		$counter++;
	}
}
            
#!/perl/bin/perl -w
$number = 123;
$sum = 0;
$temp = 0;
while($number>0)
{
	$temp = $number%10;
	$sum += $sum*10 + $temp;
	$number = $number / 10;
}			
(a) Write PHP and HTML page to get the reverse of entered string in textbox when button is clicked.
<html>
	<head>
		<title>Session management Example</title>
	</head>
	<body>
		<?php
		if(isset($_POST['submit'])) {
			$str = $_POST['text'];
			$length = strlen($str);
			for($i=$length-1;$i>=0;$i--) {
				echo $str[$i];	
			}
		}
		?>
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
			Enter your String <input type="text" name="text" />
			<input type="submit" value="Submit" name="submit" />
		</form>
	</body>
</html>			
Posted By Joydip Panchal

Make Comments..!!


Oops!! No posts from user.

Download Android App