vikassoni1033 0 Newbie Poster

Here is one code of php 2 dropdown and one button i down want button,
and use ajax in dropdown..... how can i do it?

<?php
require_once("includes/ReadAllXML.php");
$to_plaza_poi = array();
$from_plaza_poi = array();
$hasMessage = false;
$row1 = "";
$row2 = "0.00";
$row3 = "0.00";
$fromPost = "";
$toPost = "";


$error = false;
//display a single point of interest, optionally bolded
function displayPOISimple($poi_arr, $plaza_name, $is_bold)
{


$bold_start = "";


$bold_end = "";


if ($is_bold)


{


$bold_start = "<strong>";


$bold_end = "</strong>";


}


if (!empty($poi_arr))


{


echo "<dl>
\r<dt>$plaza_name</dt>
\r";


foreach ($poi_arr as $poi)


{


echo "<dd>$bold_start$poi$bold_end</dd>
\r";


}


echo "</dl>";


}


}


//dipslay the fields for the points of interest


function displayPOI($from_poi_arr, $from_plaza_name, $to_poi_arr, $to_plaza_name)


{


echo "


<!-- Start Points of Interest Bar -->


<div id=\"poibar\">


<h4>Points of Interest</h4>


";


if (!empty($from_poi_arr))


{


echo "


<dl>


<dt>$from_plaza_name</dt>";


foreach ($from_poi_arr as $poi)


{


echo "<dd>$poi</dd>
\r";


}


echo "


</dl>";


}


if (!empty($to_poi_arr))


{


echo "


<dl>


<dt>$to_plaza_name</dt>";


foreach ($to_poi_arr as $poi)


{


echo "<dd>$poi</dd>
\r";


}


}


echo "


</div>


<!-- End Points of Interest Bar -->


";


}


//initialize the fare container


$obj_fare_container = new FareContainer();


//parse plazas.xml and init the plaza array


$obj_fare_container->parse_plaza_xml();


$plaza_arr = $obj_fare_container->getPlazaArr();


$parse_fares = false;


$from = "";


$to = "";


//if this iteration is from submission, then check the variables, and, if necessary, draw the map


if (isset($_POST))


{


if (isset($_POST) && !empty($_POST))


{


$fromPost = $POST;


$parse_fares = true;


$from = strip_tags(trim($_POST));


}


else


{


$message .= "<p>Please select an onramp.</p>";


$error = true;


}


if (isset($_POST) && !empty($_POST))


{


$toPost = $POST;
$parse_fares = $parse_fares & true;


$to = strip_tags(trim($_POST));


}


else


{


$message .= "<p>Please select an offramp.</p>";


$error = true;


}


}


//parse fares.xml only if the form was submitted. This reduces unnecessary load on the server


if ($parse_fares)


{


$obj_fare_container->parse_fare_xml();


$fare_arr = $obj_fare_container->getFareArr();


foreach ($fare_arr as $obj_fare)


{


//check if our From/To variables match the entry/exit points in the XML


//If match, check if altentry or altexit points were defined, and produce a message suggesting alternative routes


if ($obj_fare->getEntryPlaza() == $from && $obj_fare->getExitPlaza() == $to)


{


$alt_entry_plaza = $obj_fare->getAltEntryPlaza();


$alt_exit_plaza = $obj_fare->getAltExitPlaza();


$from_plaza = $obj_fare_container->getPlaza($from);


$from_plaza_name = $from_plaza->getPlazaName();


$to_plaza = $obj_fare_container->getPlaza($to);


$to_plaza_name = $to_plaza->getPlazaName();


if ($alt_entry_plaza != "" || $alt_exit_plaza != "")


{


$message = "<p>You cannot travel from <strong>$from_plaza_name</strong> to <strong>$to_plaza_name</strong>.</p><p>";


$error = true;


//add the validation message to the message


$validation_msg = $obj_fare->getValidationMsg();


//if alt_entry_plaza is empty, we know that the onramp is not allowed. Otherwise, it's the offramp.


if ($alt_entry_plaza != "")


{


//there is no entry point.


if ($validation_msg != "")


{


$message .= "$validation_msg";


$message .= " at $from_plaza_name. ";


}


//obtain the entry plaza name by first obtaining the object and then the name from the object


$obj_alt_entry_plaza = $obj_fare_container->getPlaza($alt_entry_plaza);


$alt_entry_plaza_name = $obj_alt_entry_plaza->getPlazaName();


if ($alt_entry_plaza_name != "NONE")


{


$message .= "Consider traveling from <strong>$alt_entry_plaza_name</strong> instead.</p>";


}


}


else


{


//there is no entry point.


if ($validation_msg != "")


{


$message .= "$validation_msg";


$message .= " at $to_plaza_name. ";


}


//obtain the entry plaza name by first obtaining the object and then the name from the object


$obj_alt_exit_plaza = $obj_fare_container->getPlaza($alt_exit_plaza);


$alt_exit_plaza_name = $obj_alt_exit_plaza->getPlazaName();


if ($alt_exit_plaza_name != "NONE")


{


$message .= "Consider traveling to <strong>$alt_exit_plaza_name</strong> instead.</p>";


}


$error = true;


}


}


else


{
$hasMessage = true;
$row1 = $message = "<p>The toll for your trip from <strong>$from_plaza_name</strong> to <strong>$to_plaza_name</strong>:</p>";


$message .= "<p>FasTrak<sup>®</sup>: $" . $obj_fare->getEtcFare() . "<br/>";


$row2 = $obj_fare->getEtcFare();


$message .= "Cash/Credit Card: $" . $obj_fare->getCashFare() . "</p>";


$row3 = $obj_fare->getCashFare();



$onramp_x = $from_plaza->getX_Coor();


$onramp_y = $from_plaza->getY_Coor();


$offramp_x = $to_plaza->getX_Coor();


$offramp_y = $to_plaza->getY_Coor();


//grab the points of interest for display


$from_plaza_poi = $from_plaza->getPointsOfInterest();


$to_plaza_poi = $to_plaza->getPointsOfInterest();


}


break;


}


}


//if at this point there is no fare, that means that the Onramp/Offramp combination is invalid.


//this is default, in case the onramp/offramp alternative entry/exit points are not defined.


if ($message == "")


{


$from_plaza_name = $obj_fare_container->getPlazaName($from);


$to_plaza_name = $obj_fare_container->getPlazaName($to);


$message = "<p>You cannot travel from <strong>$from_plaza_name</strong> to <strong>$to_plaza_name</strong>. Please select another route.</p>";


$error = true;


}


}


?>
<!-- Start Points of Interest Bar -->
<div id="poibar"></div>
<div id="wrap">
<div id="innerwrap">
<div id="main1">
<div id="content">
<div id="leftcol">
<div id="tollform">
<form method="post" action="<?php echo $_SERVER;?>">
<div class="toll_img">
<table style="width: 95%;" border="0">
<tbody>
<tr>
<td>From</td>
<td>To</td>
</tr>
<tr>
<td>
<?php
$from_field = "<select name='from'>";
foreach ($plaza_arr as $obj_plaza)
{
if (($obj_plaza->hasSbOnramp() || $obj_plaza->hasNbOnramp()) && !$obj_plaza->isHelperPoint())
{
$from_value = $obj_plaza->getPlazaCode();
$from_label = $obj_plaza->getPlazaName();


$selected = "";
if($from == $from_value){
$selected = "selected = 'selected'";
}


$from_field .= "<option {$selected} value='{$from_value}'>{$from_label}</option>";
}
}
$from_field .= "</select>";
echo $from_field;
?>
</td>
<td>
<?php
$from_field = "<select name='to'>";
foreach ($plaza_arr as $obj_plaza)
{
if (($obj_plaza->hasSbOnramp() || $obj_plaza->hasNbOnramp()) && !$obj_plaza->isHelperPoint())
{
$from_value = $obj_plaza->getPlazaCode();
$from_label = $obj_plaza->getPlazaName();


$selected = "";
if($to == $from_value){
$selected = "selected = 'selected'";
}


$from_field .= "<option {$selected} value='{$from_value}'>{$from_label}</option>";
}
}
$from_field .= "</select>";
echo $from_field;
?>
</td>



<td colspan="2"><input class="button12" type="submit" name="submit" value="Calculate Toll" /></td>
</tr>
</tbody>
</table>


<table style="width: 94%; padding-top:4px;" border="0">
<tbody>



<?php if($hasMessage && count($_POST)) : ?>
<tr>
<td style="font-family:'oswald';">Your Toll with FasTrak     Cash / Credit Card $<b><?php echo $row3 ?></b></td>
<td style="font-family:'oswald';"></td>
</tr>
<tr>
<td style="font-size:25px; font-weight:bold; font-family: 'oswald';">$ <?php echo $row2 ?></td>
</tr>
<?php elseif(!$hasMessage && count($_POST)) : ?>
<tr>
<td colspan="2"><?php echo $message; ?></td>
</tr>
<?php else : ?>
<tr>
<td style="font-family:'oswald';">Your Toll with FasTrak     Cash / Credit Card $<b><?php echo $row3 ?></b></td>
<td style="font-family:'oswald';"></td>
</tr>
<tr>
<td style="font-size:25px; font-weight:bold; font-family: 'oswald';">$ <?php echo $row2 ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
<div id="sidebar"></div>
</div>
<div id="footer1"></div>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9230879-1");
pageTracker._trackPageview();
} catch(err) {}</script>
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.