开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜