Reputation: 765
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?
--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);
}
});
Upvotes: 0
Views: 49
Reputation: 7060
$("#dropdownlist").prop("selectedIndex", 1);
This jQuery code sets the selected option of the dropdownlist to the 2nd option.
Upvotes: 4