Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<form>
<input type="text" name="mail" placeholder="Enter you username" required/><br>
<button class="button" type="submit" onclick="window.location.href='link.html'">Continue</button>
</form>
as you can see in this code i'm using input type button and button
what i want is before redirecting me to link.html i want the input text to be required 
its redirecting me without checking the type text
any solution 
i think the button doesn't do this but i need it to redirecting me the link.html 


What I have tried:

i tried input type submit but it doesn't redirecting me to the link that i want that why i change it to button type button
Posted
Updated 19-Mar-18 9:20am

HTML
<form action="link.html">
    <input type="text" name="mail" placeholder="Enter you username" required/><br />
    <input type="submit" class="button" value="Continue" />
</form>

HTML Forms[^]
 
Share this answer
 
Comments
Bryian Tan 19-Mar-18 15:22pm    
nice, I learned something new :) ++
The current core will display the validation then redirect immediately. Here my suggestion, On click, call a function. Then, in the function check if textbox has value before redirect.

Here is an example
CP_Redirect - JSFiddle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900