Constantine Constantine - 3 years ago 80
jQuery Question

How use if from a value of a select JQuery

I have this select form

<select id="measurement" name="measurement">
<option value="" selected>Select Measurement</option>
<option value="1" selected>Measurement 1</option>
<option value="2" selected>Measurement 2</option>

and I get its selection with this

$(document).ready(function () {
$('#measurement').on('change', function () {
var selected = $(this).find('option:selected').val();
if (selected === 1) {
url: "/Kostas/measurementData.php",
type: "POST",
data: {UserID: <?php echo json_encode($UserID); ?>, MeasurementID: selected},
success: function (data, selected) {
//some code

error: function (data) {


My if statement does not work, while the MeasurementID: selected passes the correct value when I remove the if, it isn't the same case with the if statement, it doesn't recognise it as 1 when it is. How do I do this right?

Answer Source

Check the working example at [JSFiddle][1]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download