0

Sir,

I have following codes

<?php
$country="";
$capital="";
if (isset($_POST['submit']))
{
$country=$_POST['text1'];
$capital=$_POST['text2'];
echo '<script type="text/javascript">alert("The capital of " .$country. "is " . $capital)</script>';
}

if (isset($_POST['clear']))
{
$country="";
$capital="";
}
?>

<html>
<head><title>Result on same page</title>
</head>
<body>
<center>
<form name="form1" action="same_browser.php" method="post">
Country<input type="text" name="text1" value="<?php echo $country;?>"><br>
Capital<input type="text" name="text2" value="<?php echo $capital;?>"><br><br>
<input type="submit" name="submit" value="Show Result">
<input type="submit" name="clear" value="clear">
</form>
</center>
</body>
</html>

Thes does not work, please help me to locate where are errors?

It does not run this line of code

echo '<script type="text/javascript">alert("The capital of " .$country. "is " . $capital)</script>';

Thanks

Edited by vbdotnetlover: edit

2
Contributors
3
Replies
19
Views
4 Years
Discussion Span
Last Post by AARTI SHRIVAS
2

change

echo '<script type="text/javascript">alert("The capital of " .$country. "is " . $capital)</script>';

this line to

echo "<script type='text/javascript'>alert('The capital of $country is $capital')</script>";

this one

Edited by AARTI SHRIVAS

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.