0

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>
3
  • I think you want Javascript, not PHP. Have you considered Javascript? Commented Jun 25, 2015 at 7:14
  • yea i think i need js Commented Jun 25, 2015 at 7:51
  • It would be beneficial, to us, if you could create a JsFiddle as the PHP only obscures the problem for us. Additionally make an attempt to solve it yourself and show us what you have tried. Good luck! Commented Jun 25, 2015 at 7:58

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

3 Comments

And i want when the staff value is 0 , the status change to Open ( Open value=0), any helps?
ok another problem . When i want to close the ticket ( value = 1) with a Staff name ( value not 0 ) , the status change to Cheking ( value = 2) again! i mean i cant change the status value from Checking to Closed with a Staff name. The ticket is actually Closed , but in call_edit page the call_status value is still on Checking until i dont press the update button.
Here i did only that thing what you specified in question. :)
0

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 !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.