Jonathan Limon
Jonathan Limon

Reputation: 23

how to hide button when textbox value isn't null

I'm having trouble finding any documentation on how to hide a button when the field it populates has a value. All the reference articles i've found are referring to hiding a button if the value IS null.

I need "rmabutton" to be disabled or hidden if "helpdesk_ticket_custom_field_rma_210279" is already populated with a value

<input type="button" id="rmabutton" onclick="RMA()" value="Generate RMA #">
<script type="text/javascript">

function RMA(){
//formatted day
    var date = new Date();
    var d = date.getDate();
    var day = (d < 10) ? '0' + d : d;

//formatted month
    var m = date.getMonth() + 1;
    var month = (m < 10) ? '0' + m : m;

//formatted year
    var yy = date.getYear();
    var year = (yy < 1000) ? yy + 1900 : yy;

//grab agent ID
    var agent = $("helpdesk_ticket_responder_id").value;

//Isolate agent ID last 5 digits for use in RMA as agent number 
    var agent_short = agent.slice(5,10)

//grab ticket number and eliminate special characters
    var ticket = $("ticket-display-id").innerHTML.replace(/[^a-zA-Z0-9 ]/g, "");

//parse new RMA # day-month-year-agent-ticket
    var rma_number = ""+month+""+day+""+year+"-"+agent_short+"-"+ticket+"";

//replace RMA field contents with new RMA # 
  $("helpdesk_ticket_custom_field_rma_210279").value = rma_number;  
 } 
</script>

Upvotes: 0

Views: 557

Answers (2)

knives22
knives22

Reputation: 303

hi check this out http://jsfiddle.net/elviz/2z1nvg7y/

    $("#helpdesk_ticket_custom_field_rma_210279").keyup(function(){

      $("#rmabutton").hide();

    });

Upvotes: 0

Barmar
Barmar

Reputation: 782785

Use a keyup handler on the RMA input field that tests the value, and toggle the visibility of the button depending on it.

$("#helpdesk_ticket_custom_field_rma_210279").keyup(function() {
  $("#rmabutton").toggle(this.value == '');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="helpdesk_ticket_custom_field_rma_210279">
<input type="button" id="rmabutton" value="Generate RMA #">

Upvotes: 1

Related Questions