javascript - Trying to show a <tr> if an option is selected -


i've hidden row in form i'd row display when select option set "cancelled"

this how went it:

if($("option[value='cancelled']").attr("selected") == "selected"){     //remove new option when cancelled     $("option[value='new']").remove();     $("nobr").filter(function () { return $.trim(this.childnodes[0].nodevalue) === "cancel note"; }).closest("tr").show(); } 

in console, i've noticed selected attribute not dynamically change when switching between , assume that's problem i'm not sure how go fixing that.

rest of code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script><script type="text/javascript">  _spbodyonloadfunctionnames.push("hidefields");  //disables unused priority radiobox function hidefields() {     //priority - disable unchecked radiobox     var reg = document.getelementbyid("ctl00_m_g_0537f4e9_69aa_409a_b5ed_15e3624efeab_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00");     var high = document.getelementbyid("ctl00_m_g_0537f4e9_69aa_409a_b5ed_15e3624efeab_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl01");      if(reg.checked == true){         high.disabled=true;     }else{         reg.disabled=true;     }     //on item edit, set status in progress if in new     if($("option[value='new']").attr("selected") == "selected"){         //disable new         $("option[value='new']").remove();         $("option[value='completed']").remove();         $("option[value='cancelled']").remove();          //enable in progress         $("option[value='in progress']").attr("selected","selected");      }else if($("option[value='in progress']").attr("selected") == "selected"){         //remove new option         $("option[value='new']").remove();         $("option[value='in progress']").remove();         $("option[value='completed']").attr("selected","selected");         $("nobr").filter(function () { return $.trim(this.childnodes[0].nodevalue) === "cancel note"; }).closest("tr").hide();     }else if($("option[value='completed']").attr("selected") == "selected" ){         //remove new option when completed/cancelled         $("option[value='new']").remove();         $("nobr").filter(function () { return $.trim(this.childnodes[0].nodevalue) === "cancel note"; }).closest("tr").hide();     }else if($("option[value='cancelled']").is(':selected')){         //remove new option when cancelled         $("option[value='new']").remove();         $("nobr").filter(function () { return $.trim(this.childnodes[0].nodevalue) === "cancel note"; }).closest("tr").show(); }      //call orderid     orderid(); } function presaveaction() {     //check work order claimed     if ($('#content').length == 0){     alert("please claim work order typing name or email in napa user field");     return false ;     }     else { return true ;} }  //i've deprecated function - not compatible chrome/ff function findacontrol(fieldname) {    var arr = document.getelementsbytagname("!");    // comments    (var i=0;i < arr.length; i++ )    {       // match field name       if (arr[i].innerhtml.indexof(fieldname) > 0)       {         return arr[i];      }    } }  //sets order id field read in edit form function orderid() {     //set field read , change background colour     $("input[title='order id']").attr("readonly","true").css('background-color','#f6f6f6');      //call setfocus();     setfocus();     }  //sets cursor focus napa users function setfocus() {     //set focus napa user     document.getelementbyid("ctl00_m_g_0537f4e9_69aa_409a_b5ed_15e3624efeab_ctl00_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_userfield_upleveldiv").focus(); }   </script> 

i don't know triggers block of code, testing purposes i'll use change event on select. how it:

$("#myselect").on("change", function () {     var $this = $(this);     if ($this.val() == "cancelled") {         //remove new option when cancelled         $this.find("option[value='new']").remove();         $("nobr").filter(function () {             return $.trim(this.childnodes[0].nodevalue) === "cancel note";         }).closest("tr").show();     } }); 

fiddle


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -