0

I have a strange error Or I'm being dumb and when I search for my error I don't get the answer I need.

I am trying to have some javascript run if a certain key "/" is pressed in a text box.

Here is the Code:

function ClockIn(){
    var kb_press = event.keyCode;
    if(kb_press == 47)
    {
        alert("you are clocking in");
        if(document.ClockIn.status.value === "IN"){
            alert("You Cant Clock in wile you are already Clocked in\n Please try again!")
            document.ClockIn.tx_Barcode.value, document.ClockIn.status.value, document.ClockIn.name.value = "";
        }
    }
}
<form method="POST" name="ClockIn">
<lable>Type your BarCode <input type="text" name="tx_Barcode" id="tx_Barcode" class="tx_Barcode" onkeypress="ClockIn()" ></lable><br>
<lable>Is your Name? <input type="text" name="name"></lable><br>
<lable>You are currently Signed <input type="text" name="status"></lable><br>
</form>

My result is: ClockIn is not a function

2
  • Consider using an event listener instead? Commented Apr 27, 2021 at 10:23
  • 2
    Also: <lable>...? Commented Apr 27, 2021 at 10:25

1 Answer 1

6

The problem here is you've named your "ClockIn" form, so due to age-old quirks in how HTML interacts with JavaScript, the ClockIn form overwrites your global ClockIn function.

Maybe rename the form "ClockInForm"? Better yet, though, you might want to use document.getElementById("...") to refer to elements.

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

1 Comment

You're right It didn't like being called ClockIn so I changed to InCheck. Thank you

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.