How to get multiple values using jq - javascript

I want to get multiple statuses from a select when I press a button, there are about 5 options I either want to be able to get option 1 and 2 and 3 or all 5 of them but not empty ones.
What I am already doing will return 1 specific option which is optionA and If i replace this with .val() it will just get the first option in the list
$('#myButton').on('click',function(){
$('.filter__status').val("optionA");
loadList();
});
select option below
<div class="inputRow">
<label>Status:</label>
<select class="filter__status" id="status" name="index[filters][status]">
<?php foreach (Options::statuses() as $status): ?>
<option value="<?= $status ?>" <?= ($_GET['status'] === $status ? "selected" : "") ?>><?= $status ?></option>
<?php endforeach; ?>
</select>
</div>
<div id="myButton" class="button large"><i></i> <span>Show lists</span></div>

Related

How to give id to auto generated element automatically

I want to make a dropdownlist that contains something from my database, all going well until I need to give each of the option unique id
<div class="div3" >
<select id="input2" class="drop" name="a" required>
<option value="" selected disabled>a</option>
<?php while ($row1 = mysqli_fetch_array($result)) :; ?>
<option class="option"><?php echo $row1[0]; ?></option>
<?php endwhile; ?>
</select>
</div>
Put an id unique value in option tag, and order you code for make an array with html tag, for example if $row1[0] = uniqueid and $row1[1] = name
<?php while ($row1 = mysqli_fetch_array($result)){?>
<option id="<?php echo $row1[0]; ?>" class="option"><?php echo $row1[1]; ?></option>
<?php }?>
Best Regards

how to hide original dropdown list in select2

I want to use select2 for my dropdown list. The options are from a database query. What I got is there are two dropdown lists showing. The first one is the original dropdown and the second is using select2.
The select code is:
<select name="city" id="select-city" class="form-control">
<option></option>
<?php foreach ($cities as $ct) : ?>
<option value="<?php echo $ct->id ?>"><?php echo $ct->name ?></option>
<?php endforeach; ?>
</select>
And the javascript is:
<script>
$(document).ready(function () {
$("#select-city").select2();
});
</script>
I want to hide the original dropdown. How can I do this?

Attribute selected option into a variable to show input field using SQL

I need to attribute the selected value from my dropdown list into a variable that I can use in my sql query.
I know that I have to use Ajax or jQuery but I can't because I don't learn it yet
Picture 1 :
Picture 2 :
<!-- Début PHP Catégories -->
<?php
$resCat=mysqli_query($conne,$reqCat);
?>
<div class="form-group">
<label class="col-md-3 control-label">Catégorie</label>
<div class="col-md-9">
<select class="form-control select" name="categorie" id="categorie" ">
<?php
while ($rowCat= mysqli_fetch_row($resCat)) {
?>
<option value="<?php echo $rowCat[1] ?>"><?php echo $rowCat[0] ?></option>
<?php
}
$categorie = $_POST['categorie'];
?>
</select>
</div>
</div>
<!-- Fin PHP Catégories -->
Thanks
For your case you can simply use a form and when you validate the button after having selected your option you just have to recover the value of the option and make your request

How to disable drop down option if present in DB

I have a drop down menu that is populated by an array. The goal is to have each value selected only once in the drop down to prevent duplicate column values.
I found some javascript that will disable each value after its selected, but if you reload the page, nothing is greyed out in the drop down (obviously).
How would I compare the array values with the database to disable values that are already selected in all the rows on load?
$(function(){
$('select').change(function() {
$current=$(this);
$("select").not($current).children(
"option[value='" + $current.val() + "']"
).attr('disabled', "disabled");
});
});
Drop Down Menu
<td>
<div class="grid_content editable">
<span><?php echo $records['equipment']; ?></span>
<select class="gridder_input select"
name="<?php echo encrypt("equipment|".$records['id']); ?>">
<?php
foreach($equipment as $equipments) {
?>
<option value="<?php echo $equipments; ?>"
<?php
if($equipments == $records['equipment']) {
echo 'selected="selected"';
}
?>>
<?php echo $equipments; ?>
</option>
<?php
}
?>
</select>
</div>
</td>
Is there an easier way to do this than what I've suggested? I think the closest solution I've found would work something like
$("select option:contains('Value')").attr("disabled","disabled");
Where value would be replaced with something that checks the DB. Or something like the answer found here using an if else statement

Set the default value in a drop down menu where data is entered dynamically

I have a drop down menu which is populated dynamically. Im trying to set one of the options as the default value. Given that the options are populated in the drop down only at run time, I cannot use
<option selected=selected> No </option>
My code is as follows:
<div name="form.option" class="aob-div-dyn-field">
<tbody>
<tr>
<td class="label-section" >
<label class="main-label">Choose your options</label>
</td>
<td class="input-section-dyn">
<select class="main-input-select" ></select>
</td>
</tr>
</tbody>
</div>
This refers to another file which has the enum declared.
enum options {
YES:"YES"
NO: "NO"
}
This line refers the enum "options" to the field option.
attribute optional option: options "option"
Any ideas on how I can proceed with this?
Yes you can do what you need just declare the first selected option like you have and then loop through all remaining items below. Just keep it outside of the loop. If "NO" is in your loop then just check for that and continue so you don't have a double up of options. Example:
<?php $a = results_array(); ?>
<option selected=selected> No </option>
<? foreach($results as $key => $value): if( $value == 'NO' ){ continue; } ?>
<option value=<?php echo $key; ?>><?php echo $value; ?></option>
<?php endforeach; ?>

Categories