javascript - Uncaught TypeError: Cannot read property 'val' of null -


i'm new jquery , i'm getting error "uncaught typeerror: cannot read property 'val' of null" when try following. i'm trying call function check if value of textbox null , assign zero, calling id of function. know can assign directly, there many of them, feel calling function way go.

here's code it:

function fn_save {      function fn_nullconvertor(input1) {          if (document.getelementbyid("input1").val == "") {             document.getelementbyid("input1").val == 1;         }     }      if (confirm("save?")) {          fn_nullconvertor(txtnum_tracks);         var params = {             num_tracks: $.trim($("#txtnum_tracks").val())          }      } } 

thanks time, appreciate it!

there 5 problems:

  • the fn_save missing ()
  • there no element input1 id or code getting executed before dom ready.
  • there no .val property htmlelement. .value
  • you using == assignment
  • according think, after,

this:

    function fn_nullconvertor(input1) {         if (document.getelementbyid("input1").val == "") {             document.getelementbyid("input1").val == 1;         }     } 

should be:

    function fn_nullconvertor(input1) {         if (document.getelementbyid(input1).value == "") {             document.getelementbyid(input1).value = "1";         }     }         

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -