0

I'm new to html, css, and now need to use some javascript for a form (?).

I have a riddle on my page and want the user to only be able to get to the next page upon submitting the correct solution - "weeping". I have a simple submit text box form.

This is my code for the html page so far (simplified; and not sure what 'rule/constraints' to put in the "sript" bit)

Thanks a lot for your help!

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="design.css">
</head>

<body>

<p>
Now that you've read the riddle, type in your solution below to reveal the next page.
</p>

<form action="riddlesolutionnextpage.htm" onsubmit="return validate_form ( );">
<p>  Your answer: &emsp; <input type="text"> 
  <input type="submit"></p>
</form>

<script>

</script>

</body>
</html>
  • If you want to access php variable inside your javascript. Then you need to follow this `` – Sifat Haque Apr 20 '20 at 10:06
  • Also i'm curious how you getting `$_POST()` inside script? – Sifat Haque Apr 20 '20 at 10:07
  • You would start by adding a function called "validation_form" to the script tag. So that when the user clicks 'submit' on your form then it would call 'validate_form'. From there you'd try to access the 'value' of the text input field to check if it is correct. If it is wrong you'd prevent the submission of the form. But if is correct you could allow it happen normally. – MichaelJones Apr 20 '20 at 11:22
  • Also useful to know that the `validate_form` function would receive the 'form submission event' as a parameter. So `function validatie_form(event)` and that there is a `preventDefault` method on events that allow to stop them doing the thing they normally do (submit the form in this case) – MichaelJones Apr 20 '20 at 11:25
  • To access the event, I think you to use: `onsubmit="return validate_form(event);` Not sure though. – MichaelJones Apr 20 '20 at 11:30

0 Answers0