SoFunction
Updated on 2025-04-04

When outputting PHP page, js sets the selected value of the input box

The code for setting the selected value of the input box when outputting the php page is as follows:

/* Set the value of the form */
function setValue(name, value) {
var first = (0, 1),
input, i = 0,
val;
if (value === "") return;
if ("#" === first || "." === first) {
input = $(name);
} else {
input = $("[name='" + name + "']");
}

if ((0).is(":radio")) { //Radio button("[value='" + value + "']").each(function() {
 = true
});
} else if ((0).is(":checkbox")) { //Check boxif (!$.isArray(value)) {
val = new Array();
val[0] = value;
} else {
val = value;
}
for (i = 0, len = ; i < len; i++) {
("[value='" + val[i] + "']").each(function() {
 = true
});
}
} else { //Other form options directly set the value(value);
}
}

The above is the selected value of the js input box when outputting the PHP page, which I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!