简体   繁体   中英

jquery change event not firing

I am using a jQuery change event that is working fine apart from an addition I just made. What I am trying to do, is when a user selects anything other than 'NEW' from the select, then show an input element. I assumed that this would work with just an else statement, but I was wrong. I would be grateful if someone could check my code and show me where I am going wrong? Thanks

<!--- dropdown for new user addition  -->
<script language="javascript" type="text/javascript">


        $(function() {

        $("#fld_company").show();
        $("#data").hide();


        $("#fld_company").live('click', function() {
              $("#fld_fld").toggle(1000);
              $("#formMessage").toggle(1000);
        });

            $("#AUSR_company").live('change', function() {
              if($(this).val()=="new")

             {
                $("#data").slideDown(1000);

             }

        else

           {

            $("#AUSR_name").show().slideDown(1000);

           }
        });
    });

</script>
<!--- end of dropdown for new user addition -->

        <dl>
          <dt>
            <label for="AUSR_name" class="opt">Full Name:</label>
          </dt>
         <dd>
            <input id="AUSR_name" name="AUSR_name" type="text" size="32" maxlength="128" value = "" />
         </dd>
        </dl>

Based on your last comment, the below is what you need, but I have already seen that this is what you said wasn't working in the question. PLease explain in what way it wasn't working?

$("#AUSR_company").live('change', function(e) {
  if($(this).val() =="new") {
    $("#data").show();

  } else {
    e.stopPropagation();
    $("#AUSR_name").show(3000)
  }
});

Why don't you use .click() and .change() instead? You can read more about them here: http://api.jquery.com/category/events/

您的表单中没有AUSR_company输入元素

        $("#AUSR_company").live('change', function() {

应该

        $("#AUSR_name").live('change', function() {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM