Reputation: 75
I have a ticketing support system and I have some rows when in call_edit.php
file. I have 2 rows called staff
and status
. When someone sends us a ticket, the ticket status by default is open
and the staff is row is empty (0 in my code) . I want to achieve that when I change the staff value from empty (0 in my code) to a name (kitty, John or else), the status automatically changes from open
to Checking
.
This is some of my php form:
<tr><td valign="top" style="width: 150px;">Status</td>
<td><select name='call_status'>
<option value='0'<?php if($site_calls->call_status == 0){echo ' selected';}?>>Open</option>
<option value='2'<?php if($site_calls->call_status == 2){echo ' selected';}?>>Checking</option>
<option value='1'<?php if($site_calls->call_status == 1){echo ' selected';}?>>Closed</option>
<option value='3'<?php if($site_calls->call_status == 3){echo ' selected';}?>>Deleted</option>
</select>
</td></tr>
<tr><td>Staff</td><td><select name='call_staff'>
<option value="0"></option>
<?php $staff_name = $db->get_results("select user_id,user_name from site_users where user_level<>1 order by user_name;");
foreach ($staff_name as $staff )
{?>
<option value='<?php echo $staff->user_id;?>'<?php if($staff->user_id == $call_staff){echo ' selected';}?>><?php echo $staff->user_name;?></option>
<?php } ?>
</select></td></tr>
Upvotes: 0
Views: 105
Reputation: 579
Use jQuery for this.
This is your code.
<select name='call_staff'>
<option value="0"></option>
<?php $staff_name = $db->get_results("select user_id,user_name from site_users where user_level<>1 order by user_name;");
foreach ($staff_name as $staff )
{?>
<option value='<?php echo $staff->user_id;?>'<?php if($staff->user_id == $call_staff){echo ' selected';}?>><?php echo $staff->user_name;?></option>
<?php } ?>
</select>
Now jQuery for your solution.
$("[name='call_staff']").change(function(){
if((this.value)!=0)
{
$("[name='call_status']").val(2);
}
else
{
$("[name='call_status']").val(0);
}
}).change();
Upvotes: 2
Reputation: 83
You can use JQuery. Add a class on all the staff :
<option class='staff'>
And add ids on your status options :
<option id="optOpen">
<option id="optChecking">
Then create a function in your js file, or within tags adn use this :
$( ".staff" ).change(function() {
$("#optOpen").val(0);
$("#optChecking").val(1);
});
I haven't tried this code, and I guess it isn't complete, because when you delete the name you must put the options back to their original values. This is to help you start.
Don't forget to include jQuery script !
Upvotes: 0