How to get text box value in JavaScript

前端 未结 15 1735
面向向阳花
面向向阳花 2020-12-07 14:43

I am trying to use JavaScript to get the value from an HTML text box but value is not coming after white space

For example:



        
相关标签:
15条回答
  • 2020-12-07 15:13

    Set the id attribute of the input to txtJob. Your browser is acting quirky when you call getElementById.

    0 讨论(0)
  • 2020-12-07 15:14

    If you are using ASP.NET, the server-side code tags in these examples below will provide the exact control ID, even if you are using Master pages.

    Javascript:

    document.getElementById("<%=MyControlName.ClientID%>").value;
    

    JQuery:

    $("#<%= MyControlName.ClientID %>").val();
    
    0 讨论(0)
  • 2020-12-07 15:16

    If you are using any user control and want to get any text box values then you can use the below code:

    var result = document.getElementById('LE_OtherCostsDetails_txtHomeOwnerInsurance').value;
    

    Here, LE_OtherCostsDetails, is the name of the user control and txtHomeOwnerInsurance is the id of the text box.

    0 讨论(0)
提交回复
热议问题