0

I am struggling to get this to work. I have a HTML from that was working fine and popping up with a prompt asking if I want to make the task public, but I then wanted to add another part in the make public part.

I wanted to then check a value on the form if it was made public:

echo "<label>Notify Creditor Of Update?</label>\n";
echo "<select name=\"send_options\" id=\"send_options\" class=\"\">\n";
echo "<option selected=\"\" value=\"n\">No</option>\n";
echo "<option value=\"y\" selected>Yes</option>\n";
echo "</select>\n";

So I thought that creating var notify = jQuery('#send_options').val(); would select the value from the above code.

Then IF the option selected is NOT y then popup asking if I want to Notify the client, If I select OK then notify, if I click Cancel, then do nothing about notifying them.

if (confirm('Do you wish to make this task public?')) {
    // Make it public
    jQuery.get('CODE_PATH_TO_EXECUTE', function (data) {
        jQuery('#taskTopOut-<?php echo $rightId;?>').append(data);
    });

    var notify =  $('#send_options option:selected').val();
    alert(notify);
    if((notify != 'y'))
    {
        confirm('Do you wish to notify client?');
        {
        // Notify
        jQuery.get('CODE_PATH_TO_EXECUTE', function (data) {
            jQuery('#taskTopOut-<?php echo $rightId;?>').append(data);
        });

    }
} else {
    // Not notify
}
} else {
    // Not public
    jQuery.get('CODE_PATH_TO_EXECUTE', function (data) {

    });

}
3
  • 2
    and the question is ... ? Commented Jul 16, 2014 at 11:04
  • That code does not look like it would run at all at the moment: confirm('Do you wish to notify client?')) { appears to have an extra closing bracket? Commented Jul 16, 2014 at 11:08
  • Removed the additional ) issue now ive noticed is when I select something on the dropdown, the selected option still says "" Commented Jul 16, 2014 at 12:29

1 Answer 1

1

You could use to get the selected value:

   var notify =  $('#send_options option:selected').val();

LIVE DEMO

UPDATE:

I think the question is not clear that all, but after your comment you are looking for:

$('#send_options').on('change', function(){       
   var $value=this.value;
   $('#send_options option').removeAttr('selected'); //remove selected that all option
   $('#send_options option[value='+ $value+']').attr("selected", "selected") //add selected to option selected
})

DEMO UPDATED

Sign up to request clarification or add additional context in comments.

3 Comments

No, not in Firebug, however, even if I select "No" it only recognizes yes, I have edited my original post with the new inserted code so you can see where im at. I also added an alert to see which one has been selected
Ok, but whole the code is trigger from? onchange(), click()? Becouse if you see the fiddle the soluton works.
I am not sure that you completely understand what im am trying to achieve? What I want is when an option is selected, to make that the selected value. EG: IF Yes is selcted <option value=\"n\">No</option> <option value=\"y\" selected>Yes</option> OR IF No is Selected: <option value="n" selected>No</option> <option value="y">Yes</option>

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.