How to use function with parameters and check the parameters value "if condition" using JQuery
Below function was not working. please correct my mistake.
开发者_JAVA技巧function setupScript() {
OtherOnchanged('call_response', 'SPAN_Other', 'Other');
}
function OtherOnchanged (onChangedId, spanId, valueToCheck) {
if ( $("#" + onChangedId).val() == valueToCheck) {
alert ("Working");
}
}
This is fine, problem is probably somewhere else, in your HTML code.
Or ... are you calling setupScript() function ?
http://sandbox.phpcode.eu/g/8c7a0.php
<input id="call_response" value="Other"></div>
<script>
function setupScript() {
OtherOnchanged('call_response', 'SPAN_Other', 'Other');
}
function OtherOnchanged (onChangedId, spanId, valueToCheck) {
if ( $("#" + onChangedId).val() == valueToCheck) {
alert ("Working");
}
}
setupScript();
</script>
The only issue I see would be if you have no match for $("#call_response")
. For that to work, you need some DOM object with id="call_response"
like this:
<div id="call_response"></div>
Script works fine. Make sure:
- that jquery script included
- that element with id "call_response" is loaded when "setupScript()" function is executed
- that element with id "call_response" has value "Other" assigned
- that "setupScript()" function is actually executed
Do you get any javascript errors?
精彩评论