I have a database driven table where the last column in the table contains a form that repeats for each row. I want to have a day_inperson field show if the value in the spring_2021_status field is equal to "Both" Since the form is repeated on the page, it doesn't work.
Here is my code for the repeating form. The form itself works fine and inserts into the database. Just need the one field to show if it meets the value of "Both":
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" id="spring_2021_status" name="spring_2021_status">
<option></option>
<option value="In Person" <?php if (!(strcmp('In Person', ($survey->getColumnVal("spring_2021_status"))))) { echo "selected=\"selected\"";} ?>>In Person</option>
<option value="Remote" <?php if (!(strcmp('Remote', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>Remote</option>
<option value="Both" <?php if (!(strcmp('Both', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>Both</option>
<option value="N/A" <?php if (!(strcmp('N/A', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>N/A</option>
</select>
<br>
<script>
$('#spring_2021_status').on('change',function(){
if( $(this).val()==="Both"){
$("#update_status2").show()
}
else{
$("#update_status2").hide()
}
});
</script>
<div class="row" id="update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
<?php echo($survey->getColumnVal("notes")); ?></textarea>
</div>
<input type="hidden" value="<?php echo($survey->getColumnVal("theein")); ?>" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
You can use class selector inside your div update_status2 then whenever your select-box gets change use $(this).closest('form').find().. this line will get closest form from select-box and then find your div which you need to show/hide.
Demo Code :
//onchange of sleect
$('[name=spring_2021_status]').on('change', function() {
if ($(this).val() === "Both") {
//get closest form tag and then find your div
$(this).closest('form').find(".update_status2").show()
} else {
$(this).closest('form').find(".update_status2").hide()
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" name="spring_2021_status">
<option></option>
<option value="In Person" selected>In Person</option>
<option value="Remote">Remote</option>
<option value="Both">Both</option>
<option value="N/A">N/A</option>
</select>
<br>
<!--added class-->
<div class="row update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
something...</textarea>
</div>
<input type="hidden" value="abc" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" name="spring_2021_status">
<option></option>
<option value="In Person" selected>In Person</option>
<option value="Remote">Remote</option>
<option value="Both">Both</option>
<option value="N/A">N/A</option>
</select>
<br>
<div class="row update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
something...</textarea>
</div>
<input type="hidden" value="abc" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
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'];
}
?>
Friends, I have the following question:
The following code below finds the next element from the clicked select:
<div class="caixa-dependentes2">
<select name="campo0[1]" id="campo0[1]" class="form-control aa" required>
<option value="Habilitado">Habilitado</option>
<option value="Desabilitado">Desabilitado</option>
</select>
<input name="campo1[1]" class="bb" value="teste1" />
<input name="campo2[1]" class="cc" value="teste2" />
<br><br>
<select name="campo0[2]" id="campo0[2]" class="form-control aa" required>
<option value="Habilitado">Habilitado</option>
<option value="Desabilitado">Desabilitado</option>
</select>
<input name="campo1[2]" class="bb" value="test3" />
<input name="campo2[2]" class="cc" value="teste4" />
</div>
It works perfectly.
The problem is that by including the divs formatting daughters in the field, it can not find more the next element, showing them as undefined, please see the code:
<div class="caixa-dependentes2">
<div>
<select name="campo0[1]" id="campo0[1]" class="form-control aa" required>
<option value="Habilitado">Habilitado</option>
<option value="Desabilitado">Desabilitado</option>
</select>
</div>
<div><input name="campo1[1]" class="bb" value="teste1" /></div>
<div><input name="campo2[1]" class="cc" value="teste2" /></div>
<div class="clearfix"></div>
<div>
<select name="campo0[2]" id="campo0[2]" class="form-control aa" required>
<option value="Habilitado">Habilitado</option>
<option value="Desabilitado">Desabilitado</option>
</select>
</div>
<div><input name="campo1[2]" class="bb" value="test3" /></div>
<div><input name="campo2[2]" class="cc" value="teste4" /></div>
</div>
My jquery:
$('.caixa-dependentes2').on('change', '.aa', function(){
var proximo = $(this).nextAll('.bb').eq(0).val();
alert(proximo);
});
What was the mistake I made?
You can find next .bb element this way (not impossible, but EZ with jQuery):
$('.caixa-dependentes2').on('change', '.aa', function(){
/* your select element > one parent > next sibling > find .bb */
var proximo = $(this).parent().next().find('.bb').val();
alert(proximo);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="caixa-dependentes2">
<div>
<select name="campo0[1]" id="campo0[1]" class="form-control aa" required>
<option value="Habilitado">Habilitado</option>
<option value="Desabilitado">Desabilitado</option>
</select>
</div>
<div>
<input name="campo1[1]" class="bb" value="teste1" />
</div>
<div>
<input name="campo2[1]" class="cc" value="teste2" />
</div>
<div class="clearfix"></div>
<div>
<select name="campo0[2]" id="campo0[2]" class="form-control aa" required>
<option value="Habilitado">Habilitado</option>
<option value="Desabilitado">Desabilitado</option>
</select>
</div>
<div>
<input name="campo1[2]" class="bb" value="test3" />
</div>
<div>
<input name="campo2[2]" class="cc" value="teste4" />
</div>
</div>
Also on JSFiddle
I would also suggest you group/wrap the select box with inputs this way. That way you won't care where the .bb or .cc is located in document tree, you just go up to closest() wrapper and find() the text input with class specified.
I make four horizontal dropdown menu. Here is my code :
<div class="MenuSearching" id="Searching">
<div class="Menu1" id="Menu1">
<p> Lembaga</p>
<form style="margin-top:-20px;margin-left:-2px;">
<select name="DropLembaga" autofocus required id="DropLembaga">
<option value="no" selected="selected">---Choose one---</option>
<option value="FlashCom">FlashCom</option>
<option value="InterNusa">InterNusa</option>
<option value="HexaCompare">HexaCompare</option>
</select>
</form>
</div>
<div class="Menu2" id="Menu2">
<p> Paket Kursus</p>
<form style="margin-top:-20px;margin-left:-2px;">
<select name="DropBahasa" autofocus required id="DropBahasa">
<option value="no" selected="selected">---Choose one---</option>
<option value="web">Kursus Web Design</option>
<option value="flash">Kursus Flash Animation</option>
<option value="marketing">Kursus Internet Marketing</option>
</select>
</form>
</div>
<div class="Menu3" id="Menu3">
<p> Lokasi</p>
<form style="margin-top:-20px;margin-left:-3px;">
<select name="DropLokasi" autofocus required id="DropLokasi">
<option value="no" selected="selected">---Choose one---</option>
<option value="timur">Surabaya Timur</option>
<option value="barat">Surabaya Barat</option>
<option value="utara">Surabaya Utara</option>
<option value="selatan">Surabaya Selatan</option>
</select>
</form>
</div>
<div class="Menu4" id="Menu4">
<p> Harga</p>
<form style="margin-top:-20px;margin-left:-2px;">
<select name="DropHarga" autofocus required id="DropHarga">
<option value="no" selected="selected">---Choose one---</option>
<option value="harga1"> kurang dari Rp.750.000</option>
<option value="harga2">Rp.750.000 - Rp.1.500.000</option>
<option value="harga3">Rp.1.500.000 - Rp.2.500.000</option>
<option value="harga4">lebih dari Rp.2.500.000</option>
</select>
</form>
</div>
<div>
<input name="submitbutton" type="submit" id="submitbutton" formmethod="POST" value="search">
</div>
</div>
My question, how to make the submit button from these multiple dropdown (and get the results)?
Is my code above efficient?
Thank you for the answer!
First thing would be to change your form tags to divs to keep your formatting.
<div class="Menu1" id="Menu1">
<p> Lembaga</p>
<div style="margin-top:-20px;margin-left:-2px;">
<select name="DropLembaga" autofocus required id="DropLembaga">
<option value="no" selected="selected">---Choose one---</option>
<option value="FlashCom">FlashCom</option>
<option value="InterNusa">InterNusa</option>
<option value="HexaCompare">HexaCompare</option>
</select>
</div>
</div>
Next you will need to surround your entire form with <form></form> tags. I would place the open form tag just below the opening of your first div.
<div class="MenuSearching" id="Searching">
<form action="" method="post">
<div class="Menu1" id="Menu1">
.
.
.
</div>
<div class="Menu2" id="Menu2">
.
.
.
</div>
<div class="Menu3" id="Menu3">
.
.
.
</div>
<div class="Menu4" id="Menu4">
.
.
.
</div>
<div>
<input name="submitbutton" type="submit" id="submitbutton" formmethod="POST" value="search">
</div>
</form>
</div>
<form name="payment_info" id="payment_info" action="https://www.myvirtualmerchant.com/VirtualMerchant/process.do" method="post" >
<div class="check_form_cover">
<div class="check_form_txt fleft">Account Number:</div>
<div class="check_form_field fleft"><input name="ssl_card_number" id="ssl_card_number" type="text" class="check_form_field1" /></div>
<div class="clear"></div>
</div>
<div class="check_form_cover">
<div class="check_form_txt fleft">Expiry Date:</div>
<div class="check_form_field fleft"><select name="month" id="month" onchange="setOptions(document.payment_info.month.value);">
<option value="">Month</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select name="year" id="year">
<option value="">Year</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
</select>
</div>
<div class="clear"></div>
</div>
<input type="hidden" name="ssl_show_form" id="ssl_show_form" value="TRUE">
<input type="hidden" name="ssl_show_form" id="ssl_show_form" value="TRUE">
<input type="hidden" name="ssl_amount" id="ssl_amount" value="'.$total.'">
<input type="hidden" name="ssl_cvv2cvc2_indicator" id="ssl_cvv2cvc2_indicator" value="Present">
<div class="check_form_cover">
<div class="check_form_txt fleft">CVV Number:</div>
<div class="check_form_field fleft"><input name="ssl_cvv2cvc2" id="ssl_cvv2cvc2" type="text" class="check_form_field1" /></div>
<div class="clear"></div>
</div>
<div class="check_form_cover">
<div class="check_form_txt fleft"></div>
<div class="check_form_field fleft" align="right">
<input type="image" src="images/pay_now.jpg" name="payment" id="payment" value="Pay" alt="Pay">
</div>
<div class="clear"></div>
</div>
To combine the values dropdown boxes named month and year and combine them in the same form as a hidden field.
It's pretty hard to understand your question, and I'm not sure if it has any thing to do mysql.
It is combined as long as you have all the "input" under the same "form".
Hope that make sense.
ok. i have a dropdown menu. if i select student. an additional field should be added to the form and when i choose teacher..the student specific fields should be remove and teacher input fields should be added.. in short i want to remove #student_profile if i choose #teacher_profile, and vice versa.
heres my code:
Javascript
<script>
$(function() {
$(".fields").hide();
$("#role").change(function() {
switch($(this).val()){
case "3":
$(".fields").hide().parent().find("#student_profile").show();
.find("#teacher_profile").addClass('not-active');
break;
case "2":
$(".fields").hide().parent().find("#teacher_profile").show();
.find("#student_profile").addClass('not-active');
break;
}
});
});
$('#submit').click(function(){
$('div').remove('.not-active');
});
</script>
html form
<form action="add" method="post"/>
<h3>User</h3>
<div><input id="username" name="username"/></div>
<div><label for="password">Password </label> <input name="password" type="password"/></div>
div><label for="role">Role </label>
<select id="role" name="role" class="medium">
<optgroup label="Type of User">
<option value="3" />Student
<option value="2" />Teacher
</optgroup>
</select>
</div>
<div id="student_profile" class="fields">
<div class="field">
<label for="type">Course</label>
<select id="type" name="stdntCourse" class="medium">
<optgroup label="Choose Course">
<option value="BS IT" />BS IT
<option value="BS CS" />BS CS
<option value="BS IS" />BS IS
</optgroup>
</select>
</div>
</div>
<div id="teacher_profile" class="fields">
<div class="field">
<label for="type">Department/label>
<select id="type" name="stdntCourse" class="medium">
<optgroup label="Choose Course">
<option value="BS IT" />cas
<option value="BS CS" />education
<option value="BS IS" />engineering
</optgroup>
</select>
</div>
</div>
<input type="submit" id="submit" value="Add User"/>
</form>
Your html code is quite a mess (invalid) (wrong nesting, wrong self closing tags etc..)
<form action="add" method="post">
<h3>User</h3>
<div><input id="username" name="username"/></div>
<div>
<label for="password">Password </label>
<input name="password" type="password" />
</div>
<label for="role">Role </label>
<select id="role" name="role" class="medium">
<optgroup label="Type of User">
<option value="3">Student</option>
<option value="2">Teacher</option>
</optgroup>
</select>
<div id="student_profile" class="fields">
<div class="field">
<label for="type">Course</label>
<select id="type" name="stdntCourse" class="medium">
<optgroup label="Choose Course">
<option value="BS IT">BS IT</option>
<option value="BS CS">BS CS</option>
<option value="BS IS">BS IS</option>
</optgroup>
</select>
</div>
</div>
<div id="teacher_profile" class="fields">
<div class="field">
<label for="type">Department</label>
<select id="type" name="stdntCourse" class="medium">
<optgroup label="Choose Course">
<option value="BS IT">cas</option>
<option value="BS CS">education</option>
<option value="BS IS">engineering</option>
</optgroup>
</select>
</div>
</div>
<input type="submit" id="submit" value="Add User" />
</form>
In your jquery you have some issues becaus eyou use the ; at wrong places making syntax-errors
Here is a bit simplified version
$(function() {
$(".fields").hide();
$("#role").change(function() {
switch(this.value){
case "3":
$(".fields").hide()
.filter('#student_profile')
.show()
.removeClass('not-active')
.end()
.filter('#teacher_profile')
.addClass('not-active');
break;
case "2":
$(".fields").hide()
.filter('#teacher_profile')
.show()
.removeClass('not-active')
.end()
.filter('#student_profile')
.addClass('not-active');
break;
}
}).change();
$('#submit').click(function(){
$('div').remove('.not-active');
});
});
You also need to invoke the .change() at the first time manually to initialize the form.
Working demo at http://jsfiddle.net/gaby/qTgGY/1/