Find us on facebook

Aug 29, 2014

Via Points

HTML
include_once $_SERVER['DOCUMENT_ROOT'].COMMON.'/js/js_homewaypoint.php';
<input type="button" value="Add Waypoint" id="addwaypoint"/>
<div id="via-container"></div>
<input type="hidden" id="no_of_via_points" name="no_of_via_points" value=""/>
js_homewaypoint.php
<link rel="stylesheet" href="scripts/jquery/themes/redmond/jquery.autocomplete.css">
<script src="scripts/jquery/autocompleteused/jquery-1.9.1.min.js"></script>
<script src="scripts/jquery/autocompleteused/jquery-ui.min.js"></script>
<script>
$(document).ready(function()
{

var via_counter = 0;

$('#addwaypoint').click(function () {
                var str = '';
str += '<div id="via_container_' + via_counter + '"><label>Via Point No: ' + (via_counter+1) + ' <a href="javascript:void(0);" class="remove"><img src="styles/images/cross.png"></a></label>';
str += '<input type="text" id="via_point_' + via_counter + '"  class="area-point-text-input" />';
str += '<input type="hidden" id="via_point_id_' + via_counter + '"  class="via_point_id" />';
str += '<input type="hidden" id="via_point_table_' + via_counter + '"  class="area-point-text-input" />';
str += '<input type="hidden" id="via_point_type_' + via_counter + '"  class="area-point-text-input" />';
str += '<input type="hidden" id="via_point_postcode_' + via_counter + '"  class="area-point-text-input" />';
str += '<div id="via_point_error_' + via_counter + '" class="error_bg" style="display: none;">Please Enter Valid Drop Off Point</div>';
str += '</div></div>';
$("#via-container").append(str);
$(function() {
$("#via_point_" + via_counter).autocomplete({
source: "get_search_values.php",
minLength: 1,
select: function( event, ui ) {
$("#via_point_id_"+(via_counter-1)).val(ui.item.id);
$("#via_point_table_" + (via_counter-1)).val(ui.item.table);
$("#via_point_type_" + (via_counter-1)).val(ui.item.area_type);
   $("#no_of_via_points").val(via_counter);
$('#via_point_postcode_'+(via_counter-1)).val(ui.item.postcode);
if(ui.item.id != ''){
$("#via_point_" + (via_counter-1)).css("background"," url('styles/images/tick.png') right center no-repeat #ffffff");
$("#via_point_error_" + (via_counter-1)).hide();
//$("#from-point-container").hide();
//$("#from-point-container-display").show();
}
  return ui.item.label;
 },
});

});
                via_counter++;
        });

$("body").on('click', ".remove", function () {
via_counter--;
$('#via_container_' + via_counter + '').remove();
$("#no_of_via_points").val(via_counter);

});

});
</script>

when click on button we can call to php file to get something done

var no_of_via_points = $("#no_of_via_points").val();
viaString="";
for (via_counter = 0; via_counter < no_of_via_points; via_counter++) {
viaid=$("#via_point_id_"+via_counter).val();
viatable=$("#via_point_table_"+via_counter).val();
constidstring = "&via_point_id_"+via_counter+"=";
consttablestring = "&via_point_table_"+via_counter+"=";
if(viaString==""){
viaString = constidstring+ viaid+consttablestring+viatable;
}else{
viaString = viaString+constidstring+viaid+consttablestring+viatable;
}
}
var dataString = 'no_of_via_points='+no_of_via_points+viaString;
;
$.ajax({
 type: "POST",
 url: "ajax_quote.php",
 data: dataString,
 beforeSend: function(){ jQuery("#ajax_loader_quote").show(); jQuery("#quote-price-container").show(); jQuery("#reserve-button").show(); $('#load_price_ajax').hide(); },
 complete: function(){ jQuery("#ajax_loader_quote").hide(); $('#load_price_ajax').show();},
 success: function(response)
 {
$('#load_price_ajax').html(unescape(response));
 }
});

ajax_quote.php
for($via_counter=0;$via_counter<=$no_of_via_points;$via_counter++){
unset($_SESSION["via_point_id_".$via_counter]);
unset($_SESSION["via_point_table_".$via_counter]);
$_SESSION["via_point_id_".$via_counter] = (int)mysql_real_escape_string($_POST['via_point_id_'.$via_counter]);
$_SESSION["via_point_table_".$via_counter] = mysql_real_escape_string($_POST['via_point_table_'.$via_counter]);

}

No comments:

Post a Comment