Your option tags have the (double) quotes for value opened but you try to close them with single quotes. Basically HTML always has double quotes. Also the quotes which you try to close are in the end after a possible selected
. Also the status variable for the active option is not like the others ($row['status']
). Another problem is you're echoing "selected" while putting the rest in a variable.
This would be the best output you'd be able to get if the variable $status
does exist:
selected<select id=verify_(1)onchange="verifystatus(this.value)" style="width:80px;">
<option value="reason.php?status=1&user=1
So to fix this, first the echo needs to go and be replaced with string concatenation. Then we need to check the double quotes for HTML, and then you'll probably get the desired result:
$nestedData[] = '<select id="verify_('.$row['user_id'].')" onchange="verifystatus(this.value)" style="width:80px;">
<option value="reason.php?status=1&user=' .$row['user_id'] . '"' . ($row['status'] == '1' ? ' selected' : '') . '>Active</option>
<option value="reason.php?status=2&user=' . $row['user_id'] . '"' . ($row['status'] == '2' ? ' selected' : '') . '>Suspend</option>
<option value="reason.php?status=3&user=' . $row['user_id'] . '"' . ($row['status'] == '3' ? ' selected' : '') . '>Terminate</option>
</select>';
Which would output:
<select id="verify_(1)" onchange="verifystatus(this.value)" style="width:80px;">
<option value="reason.php?status=1&user=1" selected>Active</option>
<option value="reason.php?status=2&user=1">Suspend</option>
<option value="reason.php?status=3&user=1">Terminate</option>
</select>