1

This is my html code the code! But the JS is not working I tried a few things but i cant get the popup window if it less than 2

<script>
    function Check(name) {
        if (name.length < 2)
           alert("פחות משני תווים בשם");
    }
</script>

<input 
  id="Text1" 
  name="Text1" 
  type="text" 
  value="שם פרטי" 
  onmouseover="value=''" 
  onclick="Check();" 
/>
2
  • 2
    What is your code supposed to do? Commented Dec 1, 2012 at 17:59
  • Pass this.value to Check() function Commented Dec 1, 2012 at 18:05

4 Answers 4

1

You haven't quite hooked up your function correctly. You need to pass a value to it. In the context of the onclick event, this refers to the input element itself, and its value can be retrieved with this.value. You need to pass that value to your Check() function:

<input id="Text1" name="Text1" type="text" value="שם פרטי" 
    onmouseover="this.value=''" onclick="Check(this.value);" />

Likewise, you should set the value to empty with this.value='value' as I have also adjusted in your code. I don't know what you're intention is with the mouseover event, but this combination of events will only work if the user's cursor never leaves the textbox, which will certainly be counter-intuitive to many users.

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

Comments

0

Try passing a parameter to your function:-

Check(this.value);

like

<input id="Text1" name="Text1" type="text" value="שם פרטי" onmouseover="value=''" onclick="Check(document.getElementById('Text1').value);" />

Comments

0

You can pass check(this) then it will get value of that text field.

2 Comments

No, this is the input element itself, not its value.
sure, but you can use this.value
0

You should pass a parameter to your function:

<input id="Text1" name="Text1" type="text" value="שם פרטי" onmouseover="value=''" onclick="Check(this.value);" />

1 Comment

this would be a better option than document.getElementById('Text1')

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.