0

i have a something.php which will print the option of dropdownlist,\

then i load the .php file with

$("#dropdownlist").load("something.php");

after i load, the output is displayed, but when i change the selected value, in debug mode i din not saw a selected="selected" on the option of dropdownlist and i cannot set a selectedvalue to the dropdownlist also with

$("#dropdownlist").val("2");

any one know why this happen and how can i solve it?

add-on code

--print option on .php--

while (isset($StatusArr[$loopCount])) {
if ($loopCount == 0) {
    $selected = "selected='true'";
} else {
    $selected = "";
}

echo "<option value='"
. $StatusArr[$loopCount][0]
. "' "
. $selected
. " >"
. $StatusArr[$loopCount][1]
. "</option>";

$loopCount ++;
}

---call in .js----

$('#select').load("../something.php", function (respond, fstatus, xhr) {
    if (fstatus === "success") {
        if (status !== "missing") {
            $('#status').prop("selectedIndex", 3);                
        }
    } else {
        alert("Load data " + fstatus + "\n" + xhr.status + " " + xhr.statusText);
    }
});
1
  • 3
    So you want to set the 2nd option of the dropdownlist to be selected using jQuery? Can you show how the html code of the dropdownlist looks like? Commented Jun 10, 2015 at 2:27

1 Answer 1

4
$("#dropdownlist").prop("selectedIndex", 1);

This jQuery code sets the selected option of the dropdownlist to the 2nd option.

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

1 Comment

cannot, it still not able to set

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.