开发者

JQuery: if else on select dropdown

开发者 https://www.devze.com 2023-03-31 10:07 出处:网络
Hopefully I can get help from you guys..I got a simple script below but not sure why is this not working.

Hopefully I can get help from you guys..I got a simple script below but not sure why is this not working.

Wanted to limit the text length of the textarea depends on the select dropdown value. Please advise. HTML:

<select class="productoptionname_card-type" id="Option111453" name="Option111453">                                  
<option value="">Please select...</option>
<option value="1127125">Free Message Card</option>
<option value="1127126">Greeting Cart</option>
</select>
<textarea class="productoptionname_message" style="width: auto" tabindex="5"></textarea>
<span id="charsLeft"></span>

JQuery:

<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="http://jquery-limit.googlecode.com/files/jquery.limit-1.2.source.js" type="text/javascript"></script>
    <script language="javascript">
function ResetText() {
    if ( $('#Opt开发者_StackOverflowion111453 option:selected').text() == "Free Message Card" ) {
        $('textarea.productoptionname_message').limit('5','#charsLeft');
    }
    else if ( $('#Option111453 option:selected').text() == "Greeting Cart" ) {
        $('textarea.productoptionname_message').limit('10','#charsLeft');
    }
}
$().ready(function() {
    $('textarea.productoptionname_message').keyup(function() { ResetText(); });
    $('#Option111592').change(function() { ResetText(); });
});
</script>

Thanks much!


The extension (JQuery.limit) not works properly.

I just write a custom jquery limit extension for you.

you can test it here: http://jsfiddle.net/tcWHr/

0

精彩评论

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

关注公众号