0

I'm trying get the value from text box using ID but I'm getting boolean value

<input type="text" tabindex="4" class="form-control input-sm" required onkeypress="return onlycode(event,this);" maxlength="40" id="MaterialCode" name="MaterialCode" placeholder="Material Code" autocomplete="off">   
var matcode = $("#MaterialCode").val();

How to get the actual value and what's wrong my html code?

2
  • What do you mean by boolean value from text input? Define your input and output for clarification. Commented Apr 20, 2020 at 9:14
  • You can use the !! shortcut to convert a value to a boolean: var matcode = !!$("#MaterialCode").val();. If that doesn't work for you then please provide more detail in the question Commented Apr 20, 2020 at 9:18

1 Answer 1

1

You can get Boolean Value from a variable by Using !!

Example :

const falsyValue=0
console.log(!!falsyValue) //Log False
const truthyValue=1
console.log(!!truthyValue) //Log True

In your case, you need just to use !! to convert your value into boolean

var marcode = !!$("#MaterialCode").val();

Thank you and I hope this answer can help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.