Notice: Undefined index: txt1 in C:\xampp\htdocs\php\conversion.php on line 76

Notice: Undefined index: select1 in C:\xampp\htdocs\php\conversion.php on line 77

Notice: Undefined index: select2 in C:\xampp\htdocs\php\conversion.php on line 78

Notice: Undefined index: convert in C:\xampp\htdocs\php\conversion.php on line 79
error!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">


<head>

<title></title>

<link rel="stylesheet" type="text/css" href="css/cssus.css" />
<meta name="" content="">
</head>
<body>
<div id="nav">

    <a href="index.htm">Home</a>
    <a href="about.html">About us</a>
    <a href="mul.php">Multiplication Table</a>
    <a href="conversion.php">Conversion</a>
    </div>  <!--end of navigation-->

<div id="main">
<div id="logo">
    <img src="images/conversion.jpg" alt="conversion" id="conversion" height="400px" width="800px"/>
    </div>  <!--end of logo-->


<script type="text/javascript">
function validate()
{
var lbl1 =document.forms[0]['txt1'].value;
{
if(lbl1==null || lbl1==""){
document.getElementById('answer').innerHTML="*input number!";
return false;
}
}
}
</script>

<form action="conversion.php" method="get" name="form" onsubmit="return validate()">


Quantity:

<input type="text" name="txt1"  onsubmit="return validate()"/>  

<label></label>
<select name="select1">
<option></option>
<option>centigram</option>
<option>decigram</option>
<option>dekagram</option>
<option>dram</option>
<option>grain</option>
</select>

<label>To</label>
<select name="select2">
<option></option>
<option>centigram</option>
<option>decigram</option>
<option>dekagram</option>
<option>dram</option>
<option>grain</option>
</select>

<p><input type="submit" name="convert" value="convert" ></p>
<label id="answer" style="color:yellow" >

<?php
$quantity=$_GET['txt1'];
$select1=$_GET['select1'];
$select2=$_GET['select2'];
$answer=$_GET['convert'];
//centigram
if($select1=="centigram" && $select2=="centigram"):
$answer=$quantity*1;
echo"$answer centigram";
elseif($select1=="centigram" && $select2=="decigram"):
    $answer=$quantity*0.1;
    echo"$answer decigram";
elseif($select1=="centigram" && $select2=="dekagram"):
    $answer=$quantity*0.001;
    echo "$answer dekagram ";
elseif($select1=="centigram" && $select2=="dram"):
    $answer=$quantity*0.00564383391;
    echo"$answer dram";
elseif($select1=="centigram" && $select2=="grain"):
    $answer=$quantity*0.154323584;
    echo "$answer grain";
//decigram
elseif($select1=="decigram" && $select2=="decigram"):
    $answer=$quantity*1;
    echo"$answer decigram";
elseif($select1=="decigram" && $select2=="centigram"):
    $answer=$quantity*10;
    echo"$answer centigram";
elseif($select1=="decigram" && $select2=="dekagram"):
    $answer=$quantity*0.01;
    echo"$answer dekagram";
elseif($select1=="decigram" && $select2=="dram"):
    $answer=$quantity*0.0564383391;
echo"$answer dram";
elseif($select1=="decigram" && $select2=="grain"):
    $answer=$quantity*1.54323584;
    echo"$answer grain";
//dekagram
elseif($select1=="dekagram" && $select2=="dekagram"):
    $answer=$quantity*1;
    echo"$answer dekagram";
elseif($select1=="dekagram" && $select2=="centigram"):
    $answer=$quantity*1000;
    echo"$answer centigram";
elseif($select1=="dekagram" && $select2=="decigram"):
    $answer=$quantity*100;
    echo"$answer decigram";
elseif($select1=="dekagram" && $select2=="dram"):
    $answer=$quantity*5.64383391;
    echo"$answer dram";
elseif($select1=="dekagram" && $select2=="grain"):
    $answer=$quantity*154.323584;
    echo"$answer grain";
//dram 
elseif($select1=="dram" && $select2=="dram"):
    $answer=$quantity*1;
    echo"$answer dram";
elseif($select1=="dram" && $select2=="sentigram"):
    $answer=$quantity*177.18452;
    echo"$answer sentigram";
elseif($select1=="dram" && $select2=="decigram"):
    $answer=$quantity*17.718452;
    echo"$answer decigram";
elseif($select1=="dram" && $select2=="dekagram"):
    $answer=$quantity*0.17718452;
    echo"$answer dekagram";
elseif($select1=="dram" && $select2=="grain"):
    $answer=$quantity*27.34375;
    echo"$answer grain";
//grain 
elseif($select1=="grain" && $select2=="grain"):
    $answer=$quantity*1;
    echo"$answer grain";
elseif($select1=="grain" && $select2=="dram"):
    $answer=$quantity*0.0365714286;
    echo"$answer dram";
elseif($select1=="grain" && $select2=="decigram"):
    $answer=$quantity*0.6479891;
    echo"$answer decigram";
elseif($select1=="grain" && $select2=="dekagram"):
    $answer=$quantity*0.006479891;
    echo"$answer dekagram";
elseif($select1=="grain" && $select2=="centigram"):
    $answer=$quantity*6.479891;
    echo"$answer centigram";
else:
    echo"error!";
    endif;
?>

</label>
</form>


</div>

</body>
</html>

Instead of $quantity=$_GET['txt1']; use:

$quantity = isset($_GET['txt1']) ? $_GET['txt1'] : 0;

to give it a default value if it was not specified. (Next time use code tags please.)

whats the use of ? $_GET['txt1'] : 0;

It's the ternary operator (below example #1), basically an if.

how to clear the answer in the conversion when it will refresh?the answer is staying even if you close it

Please explain, I am not sure what you mean.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.