I have a problem hiding my Admin_Email_Address
with the selected value from a form with an array
the array is 0-Activated
and 1-Deactivated
What I am trying to do is if I select the 1
from the drop-down the email form is hidden and when 0
it is not hidden and can be inputted
<!-- STATUS -->
<div class="col-lg-3 col-md-4">
<?php $err = isset($_SESSION['sys_employees_edit_status_err']) ? 1 : 0; ?>
<div class="form-group">
<label for="status" class="mr-1<?php if ($err) { echo ' text-danger'; } ?>"><?php if ($err) { echo '<i class="far fa-times-circle mr-1"></i>'; } echo renderLang($lang_status); ?></label> <span class="right badge badge-success"><?php echo renderLang($label_required); ?></span>
<select class="form-control required<?php if ($err) { echo ' is-invalid'; } ?>" id="status" name="status" required>
<?php
foreach ($status_arr as $status) {
echo '<option value="' . $status[0] . '"';
if (isset($_SESSION['sys_employees_edit_status_val'])) {
if ($_SESSION['sys_employees_edit_status_val'] == $status[0]) {
echo ' selected';
}
}
echo '>' . renderLang($status[1]) . '</option>';
}
?>
</select>
<?php if ($err) {
echo '<p class="error-message text-danger mt-1">' . $_SESSION['sys_employees_edit_status_err'] . '</p>';
unset($_SESSION['sys_employees_edit_status_err']);
} ?>
</div>
</div>
<!-- ADMIN EMAL ADDRESS -->
<div class="col-lg-3 col-md-4">
<div class="form-group">
<label for="admin_email_address" class="mr-1<?php echo $err ? 'text-danger' : ''; ?>"> <?php echo $err ? '<i class="far fa-times-circle mr-1"></i>' : ''; echo "Admin Email Address" ?></label>
<span class="right badge badge-success"><?php echo renderLang($label_required); ?></span>
<input type="text" class="form-control required<?php echo $err ? ' is-invalid' : ''; ?>" id="admin_email_address" name="admin_email_address" placeholder="" required>
</div>
</div>
<script>
$(".status").keyup(function() {
if ($('select#status option:selected').val(); = 1 ) {
$('#admin_email_address').attr('hidden', true);
} else {
$('#admin_email_address').attr('hidden', false);
}
});
</script>
I tried to so many times to get the value of it but it still doesn’t work
2
Answers
I solved it now i just changed the jquery value to change so it is easier
You have below issue:
a)
.val();
is a syntax issue while doing comparison.b)
= 1
is not a comparison, it’s an assignment, so you need to fix it with== 1
.c) There is no HTML attribute
hidden
exist. You can achieve it via.toggleClass()
or.css()
using jQueryd) Since you want things to happen on change of the select box value then you need
.change()
not.keyUp()
Here is the solution:
Sample snippet: