简体   繁体   中英

HTML/ Javascript onchange won't work

This is my first question on stackoverflow.

I have a form:

 <input type="text" id="naam" onchange="naam()" name="toevoegerNaam_1"
placeholder="Uw naam" />

It's a very large form, and this is the specific code. You see the onchange="naam()"

This is the function:

<script type="text/javascript" >
function naam(){
    alert("test");

    }

</script>

This won't work!

If I do this: onchange="alert('test');" , it works fine.

And i can call the function with onclick.

I don't understand what's wrong.

Please help me! Maybe someno saw that I'm Dutch (Belgium), so sorry for my bad English, I will edit it, if my question isn't clear enough.

try using onkeyup/onkeydown for the function to execute as soon as you press the key,

because onchange will execute only when the focus from input field is changed/moved .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM