I am trying to get the total amount for the a variety of tickets that are available. from the select box, the user can chose the number of tickets he wants. in the end, the total amount is getting displayed. My issue is, on changing the selection of number of tickets, it is getting added to the previous total. i want to deduct it, and then add the correct amount. i have this running code.
This is the html i have.
<form>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>OAP</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="20">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">
£<span>20</span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>General</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="35">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">
£<span>35</span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Concession</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="50">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">
£<span>50</span>
</p>
</div>
</div>
<p class="push h20"></p>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Total</label>
</div>
<div class="col-xs-12 col-sm-4">
<p class="total">
£<span id="price-total">50</span>
</p>
</div>
This is my Jquery code.
var price_total = 0;
jQuery( '.venet-stock' ).change(function() {
price = jQuery(this).attr('data-price');
guest = jQuery( this ).val();
price_total += guest*price;
jQuery( '#price-total').text( price_total );
});
Thanks in advance.
Working Fiddle https://jsfiddle.net/t3vs4dgx/
HTML Code. Add only a Zero option to every dropdown.
<form>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>OAP</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="20">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">£<span>20</span></p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>General</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="35">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">£<span>35</span></p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Concession</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="50">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">£<span>50</span></p>
</div>
</div>
<p class="push h20"></p>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Total</label>
</div>
<div class="col-xs-12 col-sm-4">
<p class="total">£<span id="price-total">0</span></p>
</div>
</div>
</form>
JS Code. Going through all selections when one is changed and add price_total for this run
$( '.venet-stock' ).change(function() {
var price_total = 0;
$( '.venet-stock' ).each(function(i,e){
price = $(e).attr('data-price');
guest = $(e).val();
price_total += guest*price;
});
jQuery( '#price-total').text( price_total );
});
Related
I have a form in my laravel script, I want to know how to use cron job to delay the form once it is submitted. I want it to make it submit to the database after Five minutes.
Here is the HTML code to the form, I want it to post to the cron jobs first before it is sent to the database after 5 minutes.
<html>
<form method="post" action="{{action('SomeController#withdrawal')}}">
<!--............................... collapse one -->
<div class="card">
<div class="card-header bg-{{$bgmenu}}" id="headingOne" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<div class="span-icon">
<div class="fa fa-clone"> Trade</div>
</div>
<div class="span-mode"></div>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body bg-{{$bg}} shadow">
<div class="form-group">
<h5 class="text-{{$text}}">Symbol</h5>
<select type="text" id="symbol" name="symbol" placeholder="Symbol" required>
<option value="BCH/BTC">BCH/BTC</option>
<option value="XLM/USD">XLM/USD</option>
<option value="XRP/BTC">XRP/BTC</option>
<option value="XRP/EUR">XRP/EUR</option>
<option value="XRP/USD">XRP/USD</option>
<option value="ZEC/BTC">ZEC/BTC</option>
<option value="ZRX/BTC">ZRX/BTC</option>
<option value="ZRX/EUR">ZRX/EUR</option>
<option value="ZRX/USD">ZRX/USD</option>
</select>
</div>
<div class="form-group">
<h5 class="text-{{$text}}">Interval</h5>
<select type="text" id="time" name="time" value="{{Auth::user()->intv}}" class="form-control text-{{$text}} bg-{{$bg}}" placeholder="Interval" required>
<option value="1-Minute">1 min</option>
<option value="3-Minutes">3 min</option>
<option value="5-Minutes">5 min</option>
<option value="15-Minutes">15 min</option>
</select>
</div>
<div class="form-group">
<h5 class="text-{{$text}}">Amount</h5>
<input type="text" value="{{Auth::user()->buy}}" class="form-control text-{{$text}} bg-{{$bg}}" placeholder="100.00" name="amount" required>
</div>
<div class="form-group">
<h5 class="text-{{$text}}">Strike Rate</h5>
<select type="text" id="trade" name="trade" class="form-control text-{{$text}} bg-{{$bg}}" placeholder="Interval" required>
<option>Choose One....</option>
<option value="High_Sell">High Sell</option>
<option value="Highest_Sell">Highest Sell</option>
</select>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</html>
everyone! I am making a form consisting of fully drop down selectable menus where the user will populate the field. After pressing the submit form, I plan that information will be pulled from a database to display search results to the user. I am a little new to SQL and PHP, so any help would be appreciated! I attached the form and PHP code separately.
<form autocomplete="on" class="form-horizontal" action="" enctype="multipart/form-data" method="POST" name= "unit_assignments">
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="course_designation" class="col-lg-4 control-label">Course</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="course_designation" id="course_designation">
<option value="" selected disabled>Please Select</option>
<option value="_105">105</option>
<option value="_105i">105i</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="year" class="col-lg-4 control-label">Year</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="year" id="year">
<option value="" selected disabled>Please Select</option>
<option value="_2018">2018</option>
<option value="_2017">2017</option>
<option value="_2016">2016</option>
<option value="_2015">2015</option>
<option value="_2014">2014</option>
<option value="_2013">2013</option>
<option value="_2012">2012</option>
<option value="_2011">2011</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="semester" class="col-lg-4 control-label">Semester</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="semester" id="semester">
<option value="" selected disabled>Please Select</option>
<option value="fall">Fall</option>
<option value="spring">Spring</option>
<option value="summer">Summer</option>
<option value="maymester">Maymester</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="discipline" class="col-lg-4 control-label">Discipline</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="discipline" id="discipline">
<option value="" selected disabled>Please Select</option>
<option value="nat_sciences">Natural Sciences</option>
<option value="health_medicine">Health Medicine</option>
<option value="social_sciences">Social Sciences</option>
<option value="humanities">Humanities</option>
<option value="digital_humanities">Digital Humanities</option>
<option value="law">Law</option>
<option value="business">Business</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="digital_literacy" class="col-lg-4 control-label">Type</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="digital_literacy" id="digital_literacy">
<option value="" selected disabled>Please Select</option>
<option value="podcast">Podcast</option>
<option value="video">Video</option>
<option value="webpage">Webpage</option>
<option value="sparks">Sparks</option>
<option value="illustrator">Illustrator</option>
<option value="in_design">In Design</option>
<option value="canvas">Canvas</option>
<option value="pitochart">Pitochart</option>
<option value="power_point">Power Point</option>
<option value="spreadsheet">Spreadsheet</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="genre" class="col-lg-4 control-label">Genre</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="genre" id="genre">
<option value="" selected disabled>Please Select</option>
<option value="book_review">Book Review</option>
<option value="film_review">Film Review</option>
<option value="play_review">Play Review</option>
<option value="literature_review">Literature Review</option>
<option value="peer_reviewed_journal_articles">Peer Reviewed Journal Article</option>
<option value="conference_paper">Conference Paper</option>
<option value="conference_presentation">Conference Presentation</option>
<option value="grant_proposal">Grant Proposal</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="method" class="col-lg-4 control-label">Method</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="method" id="method">
<option value="" selected disabled>Please Select</option>
<option value="archival_research">Archival Research</option>
<option value="textual_analysis">Textual Analysis</option>
<option value="rhetorical_analysis">Rhetorical Analysis</option>
<option value="reviewing_the_literature">Reviewing the Literature</option>
</select>
</div>
</div>
</div>
</div>
<center>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<center>
<input class="btn btn-primary btn-block" type="submit" value="submit">
</center>
</div>
</div>
</center>
</form>
This is the PHP portion of the code. The page just keeps returning an empty number for conditions and only prints out "SELECT * FROM unit_assignments". It never ends up executing the rest of the code and I was wondering if it was because my PHP code is wrong or my form code. My page does connect to the database, so I don't think there are any database errors.I have tried varying methods of writing the PHP code but to no avail, which leaves me to believe maybe the PHP code and the form just aren't connecting.
<?php
// define the list of fields
$fields = array('course_designation', 'year', 'discipline', 'digital_literacy', 'genre', 'method');
$conditions = array();
// loop through the defined fields
foreach($fields as $field){
// if the field is set and not empty
if(!empty($_POST[$field])) {
// create a new condition while escaping the value inputed by the user (SQL Injection)
$conditions[] = "`$field` LIKE '%" . mysqli_real_escape_string($_POST[$field]) . "%'";
}
}
// }
// builds the query
$query = "SELECT * FROM unit_assignments ";
echo count($conditions);
// if there are conditions defined
if(count($conditions) > 0) {
// append the conditions
$query .= "WHERE " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
}
echo "$query";
$result = mysqli_query($mysqli_link, $query);
mysqli_close($mysqli_link);
if(isset($_POST['submit'])) {
while($row = mysqli_fetch_array($result)) {
$course_designation = $row['course_designation'];
$year = $row['year'];
$discipline = $row['discipline'];
$digital_literacy = $row['digital_literacy'];
$genre = $row['genre'];
$method = $row['method'];
echo "Course: $course_designation<br>Year: $year<br>Discipline: $discipline<br>digital_literacy: $digital_literacy<br>Genre: $genre<br>Method: $method<br>";
}
}
?>
<div class="col-lg-6 col-md-6 col-sm-12 m0 col-xs-12">
<div class="select-box">
<select class="select-menu" name="adults" onChange="getprice(this.value);">
<option value="default">Adults </option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
</div>
The above is the html code of select dropdown. the onchange of that drodown calls a javascript function. but it does not calls the getprice function.
<script type="text/javascript">
function getprice(val)
{
alert("here");
}
</script>
The bootstrap automatically changes that dropdown into
<div class="col-lg-6 col-md-6 col-sm-12 m0 col-xs-12">
<div class="select-box">
<select class="select-menu" name="adults" id="adults" onchange="getprice(this.value);" style="display: none;">
<option value="default">Adults</option>
<option value="1">1</option>
<option value="2">2</option></select>
<span class="ui-selectmenu-button ui-widget ui-state-default ui-corner-all" tabindex="0" id="adults-button" role="combobox" aria-expanded="false" aria-autocomplete="list" aria-owns="adults-menu" aria-haspopup="true" style="width: 71px;" aria-activedescendant="ui-id-4" aria-labelledby="ui-id-4" aria-disabled="false"><span class="ui-icon ui-icon-triangle-1-s"></span><span class="ui-selectmenu-text">Adults</span></span>
</div>
</div>
try this
HTML
<div class="col-lg-6 col-md-6 col-sm-12 m0 col-xs-12">
<div class="select-box">
<select class="select-menu" name="childless6" id="childless6">
<option value="default">Children < 6 </option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
</div>
JS
$(function() {
$('#childless6').on('change', function(e) {
select_val = $(this).val();
// rest of your code
});
});
I want to display all the data from table in MySQL database when I choose 'any' option. I don't know how to do that. Please look at the code below.
<form method="post" action="listing_grid.php">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="location">Property for: </label><br/>
<select name="property_for" id="beds" class="formDropdown">
<option value="Property for sale">Property for sale</option>
<option value="Property for rent">Property for rent</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="propertyType">Property Type</label><br/>
<select name="property_type" id="propertyType" class="formDropdown">
<option value="any">Any</option>
<option value="Houses">Houses</option>
<option value="Apartments">Apartments</option>
<option value="Bungalows">Bungalows</option>
<option value="Land">Land</option>
<option value="Commercial property">Commercial property</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock">
<label for="price-min">Price Range</label><br/>
<div style="float:right; margin-top:-25px;">
<div class="priceInput"><input type="text" name="price_min" id="price-min" class="priceInput" /></div>
<span style="float:left; margin-right:10px; margin-left:10px;">-</span>
<div class="priceInput"><input type="text" name="price_max" id="price-max" class="priceInput" /></div>
</div><br/>
<div class="priceSlider"></div>
<div class="priceSliderLabel"><span>0</span><span style="float:right;">800,000</span></div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="location">Location</label><br/>
<input id="tags" type="text" name="location">
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="beds">Beds</label><br/>
<select name="beds" id="beds" class="formDropdown">
<option value="any">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="baths">Baths</label><br/>
<select name="baths" id="baths" class="formDropdown">
<option value="any">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="area2">Search radius</label><br/>
<select name="area" id="area2" class="formDropdown">
<option value="any">Any</option>
<option value="0.25">within 1/4 mile</option>
<option value="0.5">within 1/2 mile</option>
<option value="1">within 1 mile</option>
<option value="3">within 3 miles</option>
<option value="5">within 5 miles</option>
<option value="10">within 10 miles</option>
<option value="20">within 20 miles</option>
<option value="30">within 30 miles</option>
<option value="40">within 40 miles</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock">
<label for="price-min">Size Range (Square Feet)</label><br/>
<div style="float:right; margin-top:-25px;">
<div class="priceInput"><input type="text" name="size_min" id="price-min1" class="priceInput" /></div>
<span style="float:left; margin-right:10px; margin-left:10px;">-</span>
<div class="priceInput"><input type="text" name="size_max" id="price-max1" class="priceInput" /></div>
</div><br/>
<div class="priceSlider1"></div>
<div class="priceSliderLabel"><span>0</span><span style="float:right;">80,000</span></div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock">
<input class="buttonColor" type="submit" name="find_property" value="FIND PROPERTIES" style="margin-top:24px;">
</div>
</div>
<div style="clear:both;"></div>
</div>
</form>
Here when i choose 'any' option, I want to display all the data from my table...
I am using query like below
$property_for=$_POST['property_for'];
$property_type=$_POST['property_type'];
$price_min=$_POST['price_min'];
$price_max=$_POST['price_max'];
$location=$_POST['location'];
$beds=$_POST['beds'];
$baths=$_POST['baths'];
$area=$_POST['area'];
$size_min=$_POST['size_min'];
$size_max = $_POST['size_max'];
$property_listing_for_sale = "";
$sql = mysqli_query($con, "SELECT * FROM properties WHERE category = '$property_for' AND bed_rooms = '$beds' AND bath_rooms = '$baths' ORDER BY date_added DESC") or die(mysqli_error($con));
I am newbie.. so help me.. Thanks in advance..
You should work with dynamic query's:
$baths = $_POST['baths'];
if ($baths == '*') {
$query = "select * from properties ";
} else {
$query = "select * from properties where baths = '$baths'"
}
Also you should learn about prepared statements.
A second way is to change your option value to %
<option value="Any">
And then you can use the following query:
select * from properties where baths like '$baths'
I have the bellow form to send PHP arrays.
In my form the area commented id duplicated on how many rooms are sekected
The form can be found below:
<div class="col-xs-4">
<label>Camere</label>
<div class="selector">
<select id='rooms' class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
</div>
<hr>
<!--START-->
<div id="room-1">
<h5 class="title">CAMERA 1</h5>
<div class="row">
<div class="col-xs-4">
<label>ADULTS</label>
<div class="selector">
<select id='adults-1' name="adults-1[]" class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="col-xs-4">
<label>Copii</label>
<div class="selector">
<select id='kids-1' name="kids-1[]" class="full-width">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
>
</select>
</div>
</div>
</div>
<div class="age-of-children no-display">
<div class="row">
<div class="col-xs-4 child-age-field">
<label>Copil 1</label>
<div class="selector validation-field">
<select class="full-width" name="kidsage-1[]"id='kidsage-1'>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</div>
</div>
</div>
</div>
<!--END-->
What i need to acomplish , ?
After sending the form on the response page i need to build an array structure based on the information send to the form.
Example:
If i select on the 2 rooms i will have the below HTML
**<!--ROOM 1-->**
<div id="room-1">
<h5 class="title">CAMERA 1</h5>
<div class="row">
<div class="col-xs-4">
<label>ADULTS</label>
<div class="selector">
<select id='adults-1' name="adults-1[]" class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="col-xs-4">
<label>Copii</label>
<div class="selector">
<select id='kids-1' name="kids-1[]" class="full-width">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
>
</select>
</div>
</div>
</div>
<div class="age-of-children no-display">
<div class="row">
<div class="col-xs-4 child-age-field">
<label>Copil 1</label>
<div class="selector validation-field">
<select class="full-width" name="kidsage-1[]"id='kidsage-1'>
<option value="0">0</option>
<option value="1">1</option>
..........................
</select>
</div>
</div>
</div>
</div>
**<!--ROOM 2-->**
<div id="room-2">
<h5 class="title">CAMERA 2</h5>
<div class="row">
<div class="col-xs-4">
<label>ADULTS</label>
<div class="selector">
<select id='adults-2' name="adults-2[]" class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="col-xs-4">
<label>Copii</label>
<div class="selector">
<select id='kids-2' name="kids-2[]" class="full-width">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
>
</select>
</div>
</div>
</div>
<div class="age-of-children no-display">
<div class="row">
<div class="col-xs-4 child-age-field">
<label>Copil 1</label>
<div class="selector validation-field">
<select class="full-width" name="kidsage-2[]"id='kidsage-1'>
<option value="0">0</option>
<option value="1">1</option>
..........................
</select>
</div>
</div>
</div>
</div>
<!--END-->
And on the first room i select 1 ADULT
on the second room i select 2 ADULTS and 1 Child who has 1 Year
I need to be outputed as:
// First Room
$rooms[] = array(array("paxType" => "Adult"));
// Second Room
$rooms[] = array(array("paxType" => "Adult"), array("paxType" => "Adult"), array("paxType" => "Child", "age" => 1));
I have tried different ways but i can manage only to input adults and child but not their age also. I need the outbut to be as the above because on the API SOAP requirements.