<html>
<head></head>
<body>
<div class="col">
<form action="#" method="post">
<select id="periodname" class="drpdwn" value=" " onchange='myFunction()'>
<?php foreach($period as $period): ?>
<option><?= $period['period']; ?></option>
<?php endforeach; ?>
</select>
</form>
</div>
<div class="col" style="width:200px">
<form action="myprofile.php" method="post" name='periodGet' id='periodGet'>
<input name='periodText' autocomplete="off" value="Period">
<input type="submit" value="Go">
</form>
</div>
</body>
</html>
that is partial of my whole system, im asking how to auto submit a form if an textbox value is change without pressing submit button or enter button thank you
html
<select id="id" class="drpdwn" value=" " onchange='getCity()'>
script
function getCity(){
var state=$('#id').val();// it should contain some value
$.ajax({
url: "<?php echo base_url() ?>getCity/"+state, //your url and values
dataType: "json",
success: function(result){
$.each( result, function( key, value ) {
//what you want to do after posting?
});
}});
}
You do not need any function to trigger onchange() of the select values. You can simply submit the form when the select value is changed using this.form.submit()
in onchange()
function as an example below.
<select id="periodname" class="drpdwn" value=" " onchange='this.form.submit()'>
$("#textF").keyup(function() {
console.log($("#textF").val());
$('#form2').delay(200).submit();
});
$("#textF2").change(function() {
console.log($("#textF2").val());
$('#form2').delay(200).submit();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="path1">
<select id="periodname" class="drpdwn" value=" " onchange='this.form.submit()'>
<option>test1 </option>
<option>test2 </option>
<option>test3 </option>
</select>
</form>
<form action="path2" id="form2">
<input type="text" id="textF" placeholder="onkeyup()">
<input type="text" id="textF2" placeholder="onchange()">
</form>
</div>