I have 2 questions if the answer to the first question is 1> I want the next answer to be auto populated as Yes. Can someone steer me in the right direction please?
<div class="field">
<!-- Number of Employees -->
<label>Number of Employees</label>
<div class="styled-select">
<select name="NoOfEmployees" class="validate[required]" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<?php
foreach (range(0, 49) as $number) {
echo '<option value="'.$number.'">'.$number.'</option>';
}
?>
<option value="50 Plus">50+</option>
</select>
</div>
</div>
<div class="field">
<!-- Employers Liability Cover Required -->
<label>Employers Liability Cover Required</label>
<div class="styled-select">
<select name="EmployersLiabilityCover" class="validate[required]" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
</div>
If the answer is 0 then I just need the next question to stay as Please Select.
use jquery onchange , give selectbox inputs seperate id,
Use jquery val() to get selectbox value
use if condition to check its greater than 0
code shown below
<div class="field">
<!-- Number of Employees -->
<label>Number of Employees</label>
<div class="styled-select">
<select name="NoOfEmployees" class="validate[required]" id="select1" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<?php
foreach (range(0, 49) as $number) {
echo '<option value="'.$number.'">'.$number.'</option>';
}
?>
<option value="50 Plus">50+</option>
</select>
</div>
</div>
<div class="field">
<!-- Employers Liability Cover Required -->
<label>Employers Liability Cover Required</label>
<div class="styled-select">
<select name="EmployersLiabilityCover" id="select2" class="validate[required]" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script>
$('#select1').on('change', function() {
if(this.value>0)
{
$("#select2").val("Yes");
}
else
{
$("#select2").val("");
}
});
</script>
Related
I'm having some trouble passing the value of some HTML elements to PHP variable. I have a PHP web app where I give the users some drop down option. What I want to do is after the user has selected the option I give than to click on a button and make some calculations based on his/her selection.
I have tried using the POST and GET method but because I'm new to php I probably did it wrong. I also try with ids but no results.
Here is the HTML code
The 1st dropdown menu :
<div>
<select id="kleidwma" onchange="kleidwmata_change(this.value);kwdikos();ypsos();"
class="form-control selectpicker kleidwmata" data-size="10" data-
style="btn-white" name="guard_kleidwmata" required >
<option value="" > </option>
<option value="12">12 MS</option>
<option value="14">14 KETE</option>
<option value="15">15 ARRIKTON</option>
<option value="16">16 KETE</option>
<option value="22">22 KETE</option>
</select>
</div>
The 2nd dropdown menu :
<div>
<select id="sigkratisi" onchange="kwdikos()" name="sigkratisi"
class="form-control sigkratisi" required>
<option value="" ></option>
<option value="metalliki" >Μεταλλική</option>
<option value="xilogonia" >Ξυλογωνία</option>
</select>
</div>
Here is the button to be clicked after the selection has been made :
<div class="row" style="margin-top:20px; margin-left: 235px;">
<div class="col-md-7">
<input type="hidden" name="tmp_calculate" value="pending" />
<button onclick="calculate()" type="button" class="btn btn-success" >
<?php echo "Υπολογισμός";?></button>
</div>
</div>
And finally here is the function that is called :
function calculate()
{
$var1 = sigkratisi;
$var2 = kleidwma;
"code to be executed base on the var1 and var2"
}
I hope it's clear enough.
Thanks in advance for your time
you can use Forms
<form name="f" action="" method="POST">
<div>
<select id="kleidwma" name="variable"
class="form-control selectpicker kleidwmata" data-size="10" data-
style="btn-white" name="guard_kleidwmata" required >
<option value="" > </option>
<option value="12">12 MS</option>
<option value="14">14 KETE</option>
<option value="15">15 ARRIKTON</option>
<option value="16">16 KETE</option>
<option value="22">22 KETE</option>
</select>
<input type="submit" value="submit" />
</div>
</form>
in PHP
<?php
if(isset($_POST['variable']))
{
echo $_POST['variable'];
}
?>
Here i have two fields such as follows
<div class="left_2 two">
<select name="abc_type" id="abc_type_2" class="form-control">
<option value="AB">LSK-AB</option>
<option value="AC">LSK-AC</option>
<option value="BC">LSK-BC</option>
</select>
</div>
<div class="left_2 one">
<select name="abc_type" id="abc_type_1" class="form-control">
<option value="A">LSK-A</option>
<option value="B">LSK-B</option>
<option value="C">LSK-C</option>
</select>
</div>
i will be using only one field at a time and the remaining field will be hidden and the problem am always getting the value A which is present in second select tag while getting submitted.how can i pass the correct value which i choosed
Here is the solution what ever field will be hidden add disabled in the input field Check the code below.
<?php
if(isset($_POST['abc_type'])){
echo $_POST['abc_type'];
}
?>
<form action="" method="post">
<div class="left_2 two">
<select name="abc_type" id="abc_type_2" class="form-control">
<option value="AB">LSK-AB</option>
<option value="AC">LSK-AC</option>
<option value="BC">LSK-BC</option>
</select>
</div>
<div class="left_2 one">
<select name="abc_type" id="abc_type_1" class="form-control">
<option value="A">LSK-A</option>
<option value="B">LSK-B</option>
<option value="C">LSK-C</option>
</select>
</div>
<input type="submit" name="submit" value="submit"/>
</form>
I'am looking for a hide show script based on parentCatId and catId!
This is the div i try to hide and or show! div class="item-post-lot-area"
<div class="item-post-lot-area">
<label for="s_lotsize">
<?php _e('Lot Area', 'ctg_housing'); ?>
</label>
<div class="row collapse prefix-radius">
<div class="item-post-area-sign columns">
<span class="prefix"><?php echo osc_get_preference('metric','ctg_housing_theme'); ?></span>
</div>
<div class="item-post-area-number columns">
<input type="number" name="s_lotsize" id="s_lotsize" value="<?php if(isset($housingOut['s_lotsize'])) { echo $housingOut['s_lotsize'];} ?>" >
</div>
</div>
</div>
what i try!
item-post-lot-area field will all time show when loading the page! And will hide when selected the following parentCatId and catId
<option value="28">Vacation</option>
<select id="catId" name="catId" class="valid">
<option value="28">Select Subcategory</option>
<option value="29">Pension House</option>
<option value="30">Inn / Motel</option>
<option value="31">Hotel & Resort</option>
</option>
</select>
<select id="catId" name="catId" class="valid">
<option value="32">Select Subcategory</option>
<option value="33">Space</option>
<option value="34">Office</option>
<option value="35">BPO</option>
<option value="36">Economic</option>
</select>
Can someone explain me how to do this?
Thanks
You're probably looking along the lines of using .on("change") to run when the select element is changed. You can then check which value (if need be) has been selected, and then use $(".item-post-lot-area").hide() to hide the div.
$("#catId").on("change", function(){
$(".item-post-lot-area").hide();
});
I'm creating a system which provide a report generator, now my problem is i dont know how to call data with the variables that i want. For example I only want the data from January // 2014 // from the account department and so on. Now, i don't know what code to show but below is the menu where user select their variables
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function showForm() {
var selopt = document.getElementById("opts").value;
if (selopt == "Tenaga Nasional Berhad") {
document.getElementById("f1").style.display = "block";
document.getElementById("f2").style.display = "none";
}
if (selopt == "Telekom Malaysia") {
document.getElementById("f2").style.display = "block";
document.getElementById("f1").style.display = "none";
}
if (selopt == 0) {
document.getElementById("f2").style.display = "none";
document.getElementById("f1").style.display = "none";
}
}
</script>
<div id="contact_form">
<h4>Pilih Ketetapan Laporan</h4>
<form method="post" name="pilih_kategori_daftar">
<label for="daerah">Daerah:</label>
<select class="required input_field" name="daerah" id="daerah" required/>
<option value="">--Pilih Daerah--</option>
<option value="Kuantan">Kuantan</option>
<option value="Maran">Maran</option>
<option value="Bentong">Bentong</option>
<option value="Raub">Lipis</option>
<option value="Jerantut">Jerantut</option>
<option value="Cameron Highlands">Cameron Highlands</option>
<option value="P.Tenggara">Pahang Tenggara</option>
<option value="Pekan">Pekan</option>
<option value="Rompin">Rompin</option>
<option value="Temerloh">Temerloh</option>
<option value="Bera">Bera</option>
<option value="Ibu Pejabat">Ibu Pejabat</option>
</select>
<div class="cleaner_h10"></div>
<label for="bulan_bill">Bulan</label>
<select class="required bill_caj" name="bulan_bill" id="bulan_bill" width="300px" required/>
<option value="">--Pilih Bulan--</option>
<option value="Januari">Januari</option>
<option value="Februari">Februari</option>
<option value="Mac">Mac</option>
<option value="April">April</option>
<option value="Mei">Mei</option>
<option value="Jun">Jun</option>
<option value="Julai">Julai</option>
<option value="Ogos">Ogos</option>
<option value="September">September</option>
<option value="Oktober">Oktober</option>
<option value="November">November</option>
<option value="Disember">Disember</option>
</select>
<div class="cleaner_h10"></div>
<label for="tahun_bill">Tahun</label>
<input type="text" maxlength="4" size="4" id="tahun_bill" name="tahun_bill" class="required year_field" placeholder="Tahun" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required/>
<div class="cleaner_h10"></div>
<label for="kategori_akaun">Kategori</label>
<select id="opts" onchange="showForm()" class="input_field" required>
<option value="0">--Pilih Kategori--</option>
<option value="Tenaga Nasional Berhad">Akaun TNB</option>
<option value="Telekom Malaysia">Akaun TM</option>
</select>
<div class="cleaner_h10"></div>
<div id="f1" style="display:none">
<form name="akaun_tnb">
<label for="jenis">Jenis Akaun</label>
<select id="opts" onchange="showForm()"class="input_field">
<option value="0">--Pilih Jenis Akaun--</option>
<option value="Rumah Pam">Rumah Pam</option>
<option value="Loji Air">Loji Air</option>
<option value="Stor">Stor</option>
</select>
</form>
</div>
<div id="f2" style="display:none">
<form name="akaun_tm">
<label for="jenis">Jenis Akaun</label>
<select id="opts" onchange="showForm()"class="input_field">
<option value="0">--Pilih Jenis Akaun--</option>
<option value="Telefon">Telefon</option>
<option value="Telefon/Streamyx">Telefon/Streamyx</option>
<option value="Streamyx">Streamyx</option>
<option value="SMS Blast">SMS Blast</option>
<option value="TM NET">TM NET</option>
</select>
</form>
</div>
</form>
</div>
search in google:
1, How to create mysqli database, tables, columns.
2, PHP, how to connect, extract, insert data from mysqli using php,
3. How to echo mysqli data into html, 4. how to submit form to php and insert data to mysqli, 5. Learn to use AJAX & JSON...this you may leave for few months:)
Im trying to get form post values and if they match certain criteria redirect only my page doesnt seem to...
I have a form with multiple input fields
HTML
<form method="post" action="?page_id=151">
<div style="display: block;" id="Q1">
<label for="vehicleType">1. What type of vehicles do you have?</label>
<select id="vehicleType" name="vehicleType">
<option selected="selected" value="choose">Please choose</option>
<option value="hgv">HGV</option>
<option value="psv">PSV</option>
<option value="lgv">LGV</option>
<option value="car">Car</option>
<option value="mixed">Mixed Fleet</option>
</select>
</div>
<div id="Q2group1">
<label for="coverageRegion">2. Do you require national or international coverage?</label>
<select id="coverageRegion" name="coverageRegion">
<option selected="selected" value="choose">Please choose</option>
<option value="national">National</option>
<option value="international">International</option>
</select>
</div>
<div id="Q2others">
<label for="pricing">2. Do you prefer a fixed weekly price or a pump-related price?</label>
<select id="pricing" name="pricing">
<option selected="selected" value="choose">Please choose</option>
<option value="fixed">Weekly fixed price</option>
<option value="pump">Pump-related price</option>
</select>
</div>
<div id="Q3group1">
<label for="locationType">3. What type of site do you prefer?</label>
<select id="locationType" name="locationType">
<option selected="selected" value="choose">Please choose</option>
<option value="truckstops">Truck stops at lowest price</option>
<option value="motorway">Branded motorway sites</option>
</select>
</div>
<div id="Q3others">
<label for="siteCoverage">3. What site coverage do you need?</label>
<select id="siteCoverage" name="siteCoverage">
<option value="choose">Please choose</option>
<option value="countysites">County</option>
<option value="nationalsites">National</option>
</select>
</div>
<div id="Q4others">
<label for="county">4. Select your county:</label>
<select id="county" name="county">
<option value="choose">Please choose</option>
<optgroup label="England">
<option>Bedfordshire</option>
<option>Berkshire</option>
<option>Bristol</option>
<option>Tyrone</option>
</optgroup>
</select></div>
<div id="searchbuttondiv"> <input type="submit" id="searchbutton" onclick="_gaq.push(['_trackEvent', 'Fuel Card Search', 'Homepage Select Criteria'])"> </div>
</form>
PHP
if ($_POST['vehicleType'] == 'car' && $_POST['pricing'] == 'fixed' && $_POST['coverageRegion'] == 'national') {
echo '<script>alert("hi");</script>';
// header('Location: /car-weekly-national/');
}
One of your conditions is falling (and because they are all bound by AND, all of the if statement fails.
Have an else statement where you var_dump all relevant variables and see what's wrong.
Sorry everyone, oversight by me, I was checking to see if the wrong variable had been posted, wouldn't have found it if it wasn't for the suggestions to add an else statement, thanks!