JavaScript validate then add points on true validation?
I'm writing a website for a school project and I want to have the user type the answer, have JavaScript validate it, and if it's true, add it to a point counter displayed on the top of the page.
How in the world should I go about this?
Is there something in开发者_C百科 particular I should be looking for?
You have to look for:
1) How to access and manipulate the DOM. You need to manipulate the counter value, for example.
2) How to add event listeners, such as onsubmit/onclick for your form.
3) How to do if statements in javascript.
This is how I would do it :
- Put Jquery on your site
- Add an event listener on the submit field button using Jquery
- In the jquery, validate the content
- If the content is validated, then change the counter using Jquery and selector
I can give you more info if you give more info. Hope this helps though
精彩评论