So, I have a download link and an input field for the email address on my website.
To upload a file, you first need to put it in your email address.
I use the form for this: the email field is the input field, and the download button is the submit button.
I like HTML5 form validation (required fields, field types, etc., everything looks very good).
The problem is that if I use onClick in my submit button, then no good validation check works.
<form> <input type="email" id="email" placeholder="Please enter email" required> <input type="submit" class="btn" onclick="downloadWin()" value="Windows"> <input type="submit" class="btn" onclick="downloadOsx()" value="Osx"> </form> <script> function downloadWin(){ event.preventDefault(); var email = $("#email").val(); if(email != ''){ if(validateEmail(email)){ location.href='http://s/index.php?page=downloadWin&email='+email; } } } function downloadOsx(){ event.preventDefault(); var email = $("#email").val(); if(email != ''){ if(validateEmail(email)){ location.href='http://s/index.php?page=downloadOsx&email='+email; } } } </script>
This may not be the cleanest way to do this, so please if you think you know the best way to tell me :)
source share