I have 3 dependent option selects and I'm trying to populate depending on previous selection with AJAX but I can't.
I'm using Laravel and this part seems to be ok.
HTML :
<div class="form-group col-md-3">
{!! Form::label('country', 'Seleccione el País') !!}</br>
<select name="country" id="country" class="form-control country" >
<option value="" disabled selected>Paises</option>
#foreach($countries as $country)
<option value="{{$country->id}}">{{$country->name}}</option>
#endforeach
</select>
</div>
<div class="form-group col-md-3">
{!! Form::label('prov', 'Seleccione la Provincia') !!}</br>
<select name="province" id="province" class="form-control province">
<option value="" disabled>Provincias</option>
</select>
</div>
<div class="form-group col-md-3">
{!! Form::label('county', 'Seleccione el Partido') !!}</br>
<select class="form-control" name="county" id="county">
<option value="" disabled >Partido</option>
</select>
</div>
<div class="form-group col-md-3">
{!! Form::label('locality', 'Seleccione la Localidad') !!}</br>
<select class="form-control" name="locality" id="locality">
<option value="" disabled >Localidad</option>
</select>
</div>
JS :
<script type="text/javascript">
$(document).ready(function(){
$(document).on('change','.country',function(){
//console.log("hmm its change");
var country_id=$(this).val();
// console.log(country_id);
var select=$(this).parent();
console.log(select);
var op=" ";
$.ajax({
type:'get',
url:'{{ URL::route('findProvince') }}',
data:{'id':country_id},
success:function(data){
//console.log(url);
//console.log(data);
//console.log(data.length);
op+='<option value="0" selected disabled>Selecciona La Provincia</option>';
for(var i=0;i<data.length;i++){
op+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
//console.log(op);
}
select.find('.province').html(" ");
select.find('.province').append(op);
//console.log(op);
},
error:function(){
}
});
});
});
</script>
I guess that the problem is in select.find, because I can see the correct response in console.log(op).
This is the op data:
<option value="0" selected disabled>Selecciona La Provincia</option>
<option value="1">Buenos Aires</option>
<option value="2">Catamarca</option>
<option value="3">Chaco</option>
<option value="4">Chubut</option>
<option value="5">Córdoba</option>
<option value="6">Corrientes</option>
<option value="7">Entre Ríos</option>
<option value="8">Formosa</option>
<option value="9">Jujuy</option>
<option value="10">La Pampa</option>
<option value="11">La Rioja</option>
<option value="12">Mendoza</option>
<option value="13">Misiones</option>
<option value="14">Neuquén</option>
<option value="15">Río Negro</option>
<option value="16">Salta</option>
<option value="17">San Juan</option>
<option value="18">San Luis</option>
<option value="19">Santa Cruz</option>
<option value="20">Santa Fe</option>
<option value="21">Santiago del Estero</option>
<option value="22">Tierra del Fuego</option>
<option value="23">Tucumán</option>
<option value="24">Ciudad Autónoma de Buenos Aires</option>
But I can't fill the select with generated options. Thanks.
The $(this).parent() stored in your select variable will refer to the parent div of .country tag what means when you try selec.find(".province") the selector will not find the element since there's no element with the province class inside the div, What I suggest is to target the select with the id (that should be unique) using :
var select = $("#province");
Then replace :
select.find('.province').html(" ");
select.find('.province').append(op);
By :
select.html(op);
Related
Here i want the div to be shown if the specified value is present or selected and the div should be hide if the specified value is not selected.
here is my code
<select name="result" id="result" class="form-control select2" style="width: 70%" multiple>
<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="q">Q</option>
</select>
here is html
<div class="form-group" id="qaranty_count_full">
<label for="recipient-name" class="col-form-label">Count:</label>
<input type="number" required name="qaranty_count" class="form-control" id="qaranty_count" value="1">
</div>
Here is the script
<script type="text/javascript">
$(document).ready(function(){
$('#qaranty_count_full').hide();
$("#result").change(function(){
if($('option:selected', this).val()=='q')
{
$('#qaranty_count_full').show();
$('#qaranty_count').prop('required', true);
}
else
{
$('#qaranty_count_full').hide();
$('#qaranty_count').prop('required', false);
}
});
});
</script>
in this case if i choose q first time the div becomes visible and if i choose q as second or third value the div is not becoming visible,the div should remain visible if q is selected,hope understood my problem
You can try this code.
$(document).ready(function(){
$("#result").change(function(){
if($.inArray("q", $(this).val()) !== -1){
$('#qaranty_count_full').show();
$('#qaranty_count').prop('required', true);
}else{
$('#qaranty_count_full').hide();
$('#qaranty_count').prop('required', false);
}
});
});
Here is a codepen I have created.
https://codepen.io/smitraval27/pen/BrpPPN
You could do like this, using .each, and loop the selected array.
Stack snippet
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="result" id="result" class="form-control select2" style="width: 70%" multiple>
<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="q">Q</option>
</select>
<div class="form-group" id="qaranty_count_full">
<label for="recipient-name" class="col-form-label">Count:</label>
<input type="number" required name="qaranty_count" class="form-control" id="qaranty_count" value="1">
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#qaranty_count_full').hide();
$("#result").change(function(){
$('#qaranty_count_full').hide();
$('#qaranty_count').prop('required', false);
$('option:selected', this).each(function(i,sel){
if ($(sel).val() == 'q') {
$('#qaranty_count_full').show();
$('#qaranty_count').prop('required', true);
}
});
});
});
</script>
I am new to PHP & jQuery and I was constructing a repeater field for my Wordpress site but I will skip how I build it. Right now, I am trying to figure out an answer on how to get last loop counter in PHP foreach loop and apply that last counter number as initial counter value for jQuery variable. I'm not sure if this is possible because what I am trying to do is using the server-side data for client-side processing.
That's all for the intro, now here is my example PHP code:-
$x = -1;
foreach ($something as $some){
$x++; // Let say $some has total of 3, so $x will provide counter such as 0, 1 & 2
}
And I am trying to apply the last PHP counter value as jQuery initial counter value so that it will continue the count:-
var x = *the last php counter which is 2*;
var max = 20;
if(x < max){
x++;
// The 'x' will continue the count as 3, 4, 5,...
}
I've been trying many methods before this and it was futile. Right now I think the thing that I need to figure out for first is how to retrieve the PHP loop counter into outside the loop, I guess... But while I am figuring it out, I would really be thankful to you guys if you guys able to help me as I am new to this stuff.
EDIT:-
It seems that using '<?php echo $x; ?>'; for displaying the value in my jQuery makes my jQuery execution does not work at all.
Here's the full HTML-PHP code and jQuery code with '<?php echo $x; ?>'; inserted:-
HTML-PHP:-
<?php
$user_edu = unserialize(base64_decode($current_user->education));
$x = -1;
foreach(rsort($user_edu,SORT_NUMERIC) as $edu);
foreach ($user_edu as $edu){
$x++;
echo "
<div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 field-label-size' id='p-custom-color'>
School Name
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 form-group-2 p-custom'>
<input type='text' name='education[" . $x . "][school]' class='form-control field-custom' placeholder='Your School Name' value='" . $edu['school'] . "'/>
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 field-label-size' id='p-custom-color'>
Concentration
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 form-group-2 p-custom'>
<input type='text' name='education[" . $x . "][concentration]' class='form-control field-custom' placeholder='Your Course/Program Name' value='" . $edu['concentration'] . "'/>
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 field-label-size' id='p-custom-color'>
Period
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 field-label-size form-group-2 p-custom'>
<div class='field-spacing'>
<div class='col-sm-6 col-xs-6' id='col-padding-left'>
<select name='education[" . $x . "][start_year]' class='form-control field-custom'>
<option value='' disabled>Start Year</option>
<option value='" . $edu['start_year'] . "' selected>" . $edu['start_year'] . "</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>
<option value='2010'>2010</option>
<option value='2009'>2009</option>
<option value='2008'>2008</option>
<option value='2007'>2007</option>
<option value='2006'>2006</option>
<option value='2005'>2005</option>
<option value='2004'>2004</option>
<option value='2003'>2003</option>
<option value='2002'>2002</option>
<option value='2001'>2001</option>
<option value='2000'>2000</option>
<option value='1999'>1999</option>
<option value='1998'>1998</option>
<option value='1997'>1997</option>
<option value='1996'>1996</option>
<option value='1995'>1995</option>
<option value='1994'>1994</option>
<option value='1993'>1993</option>
<option value='1992'>1992</option>
<option value='1991'>1991</option>
<option value='1990'>1990</option>
<option value='1989'>1989</option>
<option value='1988'>1988</option>
<option value='1987'>1987</option>
<option value='1986'>1986</option>
<option value='1985'>1985</option>
<option value='1984'>1984</option>
<option value='1983'>1983</option>
<option value='1982'>1982</option>
<option value='1981'>1981</option>
<option value='1980'>1980</option>
<option value='1979'>1979</option>
<option value='1978'>1978</option>
<option value='1977'>1977</option>
<option value='1976'>1976</option>
<option value='1975'>1975</option>
<option value='1974'>1974</option>
<option value='1973'>1973</option>
<option value='1972'>1972</option>
<option value='1971'>1971</option>
<option value='1970'>1970</option>
<option value='1969'>1969</option>
<option value='1968'>1968</option>
<option value='1967'>1967</option>
<option value='1966'>1966</option>
<option value='1965'>1965</option>
<option value='1964'>1964</option>
<option value='1963'>1963</option>
<option value='1962'>1962</option>
<option value='1961'>1961</option>
<option value='1960'>1960</option>
<option value='1959'>1959</option>
<option value='1958'>1958</option>
<option value='1957'>1957</option>
<option value='1956'>1956</option>
<option value='1955'>1955</option>
<option value='1954'>1954</option>
<option value='1953'>1953</option>
<option value='1952'>1952</option>
<option value='1951'>1951</option>
<option value='1950'>1950</option>
<option value='1949'>1949</option>
<option value='1948'>1948</option>
<option value='1947'>1947</option>
</select>
</div>
<div class='col-sm-6 col-xs-6' id='col-padding-right'>
<select name='education[" . $x . "][end_year]' class='form-control field-custom'>
<option value='' disabled>Start Year</option>
<option value='" . $edu['end_year'] . "' selected>" . $edu['end_year'] . "</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>
<option value='2010'>2010</option>
<option value='2009'>2009</option>
<option value='2008'>2008</option>
<option value='2007'>2007</option>
<option value='2006'>2006</option>
<option value='2005'>2005</option>
<option value='2004'>2004</option>
<option value='2003'>2003</option>
<option value='2002'>2002</option>
<option value='2001'>2001</option>
<option value='2000'>2000</option>
<option value='1999'>1999</option>
<option value='1998'>1998</option>
<option value='1997'>1997</option>
<option value='1996'>1996</option>
<option value='1995'>1995</option>
<option value='1994'>1994</option>
<option value='1993'>1993</option>
<option value='1992'>1992</option>
<option value='1991'>1991</option>
<option value='1990'>1990</option>
<option value='1989'>1989</option>
<option value='1988'>1988</option>
<option value='1987'>1987</option>
<option value='1986'>1986</option>
<option value='1985'>1985</option>
<option value='1984'>1984</option>
<option value='1983'>1983</option>
<option value='1982'>1982</option>
<option value='1981'>1981</option>
<option value='1980'>1980</option>
<option value='1979'>1979</option>
<option value='1978'>1978</option>
<option value='1977'>1977</option>
<option value='1976'>1976</option>
<option value='1975'>1975</option>
<option value='1974'>1974</option>
<option value='1973'>1973</option>
<option value='1972'>1972</option>
<option value='1971'>1971</option>
<option value='1970'>1970</option>
<option value='1969'>1969</option>
<option value='1968'>1968</option>
<option value='1967'>1967</option>
<option value='1966'>1966</option>
<option value='1965'>1965</option>
<option value='1964'>1964</option>
<option value='1963'>1963</option>
<option value='1962'>1962</option>
<option value='1961'>1961</option>
<option value='1960'>1960</option>
<option value='1959'>1959</option>
<option value='1958'>1958</option>
<option value='1957'>1957</option>
<option value='1956'>1956</option>
<option value='1955'>1955</option>
<option value='1954'>1954</option>
<option value='1953'>1953</option>
<option value='1952'>1952</option>
<option value='1951'>1951</option>
<option value='1950'>1950</option>
<option value='1949'>1949</option>
<option value='1948'>1948</option>
<option value='1947'>1947</option>
</select>
</div>
</div>
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 p-custom text-center remove_field'>
<button type='button' class='btn btn-block button-cont-custom'><span class='glyphicon glyphicon-chevron-up' id='glyphicon-menu-right-margin'></span> Remove Field</button>
</div>
<div class='col-sm-6 col-sm-offset-3 col-xs-12 text-center'>
<hr id='hr-field'/>
</div>
</div>
";
?>
<div class='repeater-edu'>
// The repeater will go here
</div>
<!----------------- Repeater Button ----------------->
<div class="col-sm-6 col-sm-offset-3 col-xs-12 text-center">
<hr id="hr-field"/>
</div>
<div class="col-sm-6 col-sm-offset-3 col-xs-12 p-custom text-center">
<button type="button" class="btn btn-block button-cont-custom add-field-edu"><span class="glyphicon glyphicon-plus" id="glyphicon-menu-right-margin"></span> Add More Field</button>
</div> // The jQuery execution call
jQuery:-
$(document).ready(function(){
$('.remove_field').click(function(){
$(this).parent('div').remove();
})
});
$(document).ready(function(){
var max_fields = 20; // Maximum input boxes allowed
var wrapper = $(".repeater-edu"); // Fields wrapper
var add_field = $(".add-field-edu"); // Add button ID
var x = '<?php echo $x; ?>'; // Initlal text box count
$(add_field).click(function(e){ // On add input button click
e.preventDefault(); // Preventing action from executed?
if(x < max_fields){ // Max input box allowed
x++; // Text box increment
$(wrapper).append('<div><div class="col-sm-6 col-sm-offset-3 col-xs-12 text-center"><hr id="hr-field"/></div><div class="col-sm-6 col-sm-offset-3 col-xs-12 field-label-size" id="p-custom-color">School Name</div><div class="col-sm-6 col-sm-offset-3 col-xs-12 form-group-2 p-custom"><input type="text" name="education["'+(x)+'"][school]" class="form-control field-custom" placeholder="Your School Name"/></div><div class="col-sm-6 col-sm-offset-3 col-xs-12 field-label-size" id="p-custom-color">Concentration</div><div class="col-sm-6 col-sm-offset-3 col-xs-12 form-group-2 p-custom"><input type="text" name="education["'+(x)+'"][concentration]" class="form-control field-custom" placeholder="Your Course/Program Name"/></div><div class="col-sm-6 col-sm-offset-3 col-xs-12 field-label-size" id="p-custom-color">Period</div><div class="col-sm-6 col-sm-offset-3 col-xs-12 field-label-size form-group-2 p-custom"><div class="field-spacing"><div class="col-sm-6 col-xs-6" id="col-padding-left"><select name="education["'+(x)+'"][start_year]" class="form-control field-custom"><option value="" disabled selected>Start Year</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><option value="2010">2010</option><option value="2009">2009</option><option value="2008">2008</option><option value="2007">2007</option><option value="2006">2006</option><option value="2005">2005</option><option value="2004">2004</option><option value="2003">2003</option><option value="2002">2002</option><option value="2001">2001</option><option value="2000">2000</option><option value="1999">1999</option><option value="1998">1998</option><option value="1997">1997</option><option value="1996">1996</option><option value="1995">1995</option><option value="1994">1994</option><option value="1993">1993</option><option value="1992">1992</option><option value="1991">1991</option><option value="1990">1990</option><option value="1989">1989</option><option value="1988">1988</option><option value="1987">1987</option><option value="1986">1986</option><option value="1985">1985</option><option value="1984">1984</option><option value="1983">1983</option><option value="1982">1982</option><option value="1981">1981</option><option value="1980">1980</option><option value="1979">1979</option><option value="1978">1978</option><option value="1977">1977</option><option value="1976">1976</option><option value="1975">1975</option><option value="1974">1974</option><option value="1973">1973</option><option value="1972">1972</option><option value="1971">1971</option><option value="1970">1970</option><option value="1969">1969</option><option value="1968">1968</option><option value="1967">1967</option><option value="1966">1966</option><option value="1965">1965</option><option value="1964">1964</option><option value="1963">1963</option><option value="1962">1962</option><option value="1961">1961</option><option value="1960">1960</option><option value="1959">1959</option><option value="1958">1958</option><option value="1957">1957</option><option value="1956">1956</option><option value="1955">1955</option><option value="1954">1954</option><option value="1953">1953</option><option value="1952">1952</option><option value="1951">1951</option><option value="1950">1950</option><option value="1949">1949</option><option value="1948">1948</option><option value="1947">1947</option></select></div><div class="col-sm-6 col-xs-6" id="col-padding-right"><select name="education["'+(x)+'"][end_year]" class="form-control field-custom"><option value="" disabled selected>End Year</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><option value="2010">2010</option><option value="2009">2009</option><option value="2008">2008</option><option value="2007">2007</option><option value="2006">2006</option><option value="2005">2005</option><option value="2004">2004</option><option value="2003">2003</option><option value="2002">2002</option><option value="2001">2001</option><option value="2000">2000</option><option value="1999">1999</option><option value="1998">1998</option><option value="1997">1997</option><option value="1996">1996</option><option value="1995">1995</option><option value="1994">1994</option><option value="1993">1993</option><option value="1992">1992</option><option value="1991">1991</option><option value="1990">1990</option><option value="1989">1989</option><option value="1988">1988</option><option value="1987">1987</option><option value="1986">1986</option><option value="1985">1985</option><option value="1984">1984</option><option value="1983">1983</option><option value="1982">1982</option><option value="1981">1981</option><option value="1980">1980</option><option value="1979">1979</option><option value="1978">1978</option><option value="1977">1977</option><option value="1976">1976</option><option value="1975">1975</option><option value="1974">1974</option><option value="1973">1973</option><option value="1972">1972</option><option value="1971">1971</option><option value="1970">1970</option><option value="1969">1969</option><option value="1968">1968</option><option value="1967">1967</option><option value="1966">1966</option><option value="1965">1965</option><option value="1964">1964</option><option value="1963">1963</option><option value="1962">1962</option><option value="1961">1961</option><option value="1960">1960</option><option value="1959">1959</option><option value="1958">1958</option><option value="1957">1957</option><option value="1956">1956</option><option value="1955">1955</option><option value="1954">1954</option><option value="1953">1953</option><option value="1952">1952</option><option value="1951">1951</option><option value="1950">1950</option><option value="1949">1949</option><option value="1948">1948</option><option value="1947">1947</option></select></div></div></div><div class="col-sm-6 col-sm-offset-3 col-xs-12 p-custom text-center remove_field"><button type="button" class="btn btn-block button-cont-custom"><span class="glyphicon glyphicon-chevron-up" id="glyphicon-menu-right-margin"></span> Remove Field</button></div></div>'); // Add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ // User click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
You can simple do this like
$x = -1;
foreach ($something as $some){
$x++;
}
and then you can assign the value of $x in your javascript code like this
var x = '<?php echo $x; ?>';
var max = 20;
if(x < max){
x++;
// The 'x' will continue the count as 3, 4, 5,...
}
You can add a hidden element to DOM and assign the value of $x to it. Then in jQuery you can take the value from the hidden element.
Example
In PHP:
... ...
... ...
Your PHP code upto "repeater-edu"
... ...
<input type="hidden" name="last_counter_of_loop" id="last_counter_of_loop" value="<?php echo $x; ?>"/>
<div class='repeater-edu'>
... ... ...
... ... ...
Then in your JQuery code:
var x = $("#last_counter_of_loop").val()
... ... ...
rest of your code
... ... ...
I hope it will work.
Thanks.
take click event as:
$(document).on("click",".add-field-edu",function(e){
...
});
More simpler way
<?php
$x=count($something)-1;
<script>
$(<you DOM object>).ready(function(){
var x = '<?php echo $x; ?>';
var max = 20;
if(x < max){
x++;
}
})
</script>
?>
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>
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:)
I have a script to echo the user's selection:
<script>
function onSuccess(data, status)
{
data = $.trim(data);
$("#car-check").text(data);
}
function onError(data, status)
{
// handle an error
}
$(document).ready(function() {
$("#submit").click(function(){
var formData = $("#car-locationform").serialize();
$.ajax({
type: "POST",
url: "pages/callajax.php",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
return false;
});
});
</script>
The selection area:
<ul class="print-menu">
<li>
<label for="select-choice-0" class="select">Parking Method:</label>
<select name="parkingoption" id="parkingoptions" data-theme="b" data-overlay-theme="d" data-native-menu="false" tabindex="-1">
<option value="">Select One</option>
<option value="Self Parking">Self Parking</option>
<option value="auto">Valet Parking</option>
</select>
</li>
<li>
<div class="self carlocation">
<h1>Enter Car Location:</h1>
<label for="select-choice-0" class="select">Floor:</label>
<select name="locationfloor" id="locationfloor" data-theme="b" data-overlay-theme="d" data-native-menu="false" tabindex="-1">
<option value="">Floor Select</option>
<option value="1">F1</option>
<option value="2">F2</option>
<option value="3">F3</option>
<option value="4">F4</option>
</select>
</div>
</li>
<li>
<div class="self car-position">
<label for="select-choice-0" class="select">Row:</label>
<select name="select-choice-15" id="positionrow" data-theme="b" data-overlay-theme="d" data-native-menu="false" tabindex="-1">
<option value="">Row Select</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>
</li>
<li>
<div class="self car-section">
<label for="select-choice-0" class="select">Section:</label>
<select name="select-choice-15" id="positionrow" data-theme="b" data-overlay-theme="d" data-native-menu="false" tabindex="-1">
<option value="">Section Select</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="G">G</option>
</select>
</div>
</li>
<li>
<div class="self car-section">
<label for="select-choice-0" class="select">Spot:</label>
<select name="select-choice-15" id="position-row" data-theme="b" data-overlay-theme="d" data-native-menu="false" tabindex="-1">
<option value="">Spot Select</option>
<option value="1-A">1-A</option>
<option value="2-B">2-B</option>
<option value="3-C">3-C</option>
<option value="4-D">4-D</option>
<option value="5-E">5-E</option>
<option value="6-F">6-F</option>
<option value="7-G">7-G</option>
</select>
</div>
</li>
<div class="self car-submit">
<button id="submit" type="submit" name="submit" value="submit" data-theme="b">Submit</button>
</div>
</ul>
<div id="car-check"></div>
Ajax Page:
<?php
$parktype = $_POST["parkingoption"];
$carfloor = $_POST["locationfloor"];
echo "<h1>Park Type: $parktype </h1>" ;
echo "<br/>";
echo "<span> Park Type: $parktype </span>";
?>
what ever the user selects will end up in #car-check. But for some reason the HTML inside of the echo just comes out as text. I only started with $parktype for the time being just to test.
Any help will greatly be appreciated, thanks!
UPDATE --
Thanks everyone I feel completely stupid not noticing that.
Change $("#car-check").text(data); to $("#car-check").html(data);
Use dataType:'html' :
$.ajax({
type: "POST",
dataType:'html',
url: "pages/callajax.php",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
And change:
$("#car-check").text(data);
To:
$("#car-check").html(data);