JavaScript Testing input length

I want alert to pop if input letters length is equal to 0 but it is not working

<div class="rame">
    <input type=text placeholder="Name" style="position: relative; right:-750px" id="inp1">
    <input type=text placeholder="Name2" style="position: relative; right:-250px" id="inp2">
    <button onclick="check()">submit</button>
</div>

<script>
    function check() {
        var a = document.getElementById("inp1");
        var b = document.getElementById("inp2");
        if (a.length = 0) {
            alert("Hello World")
        }
    }
</script>
Answer:1
  1. With getElementById you will get an ELEMENT
  2. In pure JavaScript length is meant for strings
  3. If you want to compare you have to use double =

I think you tried this:

<div class="rame">
        <input type=text placeholder="Name" style="position: relative; right:-750px" id="inp1">
        <input type=text placeholder="Name2" style="position: relative; right:-250px" id="inp2">
        <button onclick="check()">submit</button>
    </div>

    <script>
        function check() {
            var a = document.getElementById("inp1");
            var b = document.getElementById("inp2");
            if (a.value.length == 0) {
                alert("Hello World")
            }
        }
    </script>
Answer:2

I am using only Javascript. I have the following string : ?pn1=age&pn2=name&pv1=12&pv2=alice What I need to do, is have the following outcome : age:12|name:alice I thought of a way to ...

I am using only Javascript. I have the following string : ?pn1=age&pn2=name&pv1=12&pv2=alice What I need to do, is have the following outcome : age:12|name:alice I thought of a way to ...

  1. sort array custom javascript
  2. sort array custom php
  3. sort array custom order
  4. sort array custom order swift
  5. sort array custom ruby
  6. sort array custom objects
  7. array sort custom comparator
  8. array sort custom function
  9. sort custom array swift
  10. array sort custom function php
  11. array sort custom java
  12. array sort custom
  13. array sort custom comparator java
  14. array sort custom comparator c#
  15. array sort custom c#
  16. sort custom array typescript
  17. arraylist custom sort
  18. javascript sort array custom comparator
  19. sort array of custom objects swift
  20. python sort array custom

I have a screen where I would like to calculate the next x and y based on angle. The first footstep is this example starts at Step 1. How can I calculate the next footstep where I want to increase ...

I have a screen where I would like to calculate the next x and y based on angle. The first footstep is this example starts at Step 1. How can I calculate the next footstep where I want to increase ...

I have buttons that I make with an each sentence in jade each u in requests form.form-horizontal(method="post") input(type='button', value='Accept #{u.friend}', onclick='doAction(this....

I have buttons that I make with an each sentence in jade each u in requests form.form-horizontal(method="post") input(type='button', value='Accept #{u.friend}', onclick='doAction(this....

  1. get value button jquery
  2. get value button javascript
  3. get value button
  4. get value button php
  5. get value button js
  6. get value button onclick
  7. get value button react
  8. get value button click jquery
  9. get value button submit jquery
  10. get value button tkinter
  11. get value button click
  12. get value button android
  13. get value button form
  14. get value button jsp
  15. getting button value html
  16. get button value onclick javascript
  17. get button value onclick react
  18. get button value angular
  19. get button value onclick jquery
  20. get button value using jquery

It's a simple question. If I click the box , I want to move 200px to the left. but it's hard to me Please help me! where's the problem? <style> .box { width: 200px; height: 200px; ...

It's a simple question. If I click the box , I want to move 200px to the left. but it's hard to me Please help me! where's the problem? <style> .box { width: 200px; height: 200px; ...

  1. mouse click wont move