Link to home
Create AccountLog in
Avatar of ivan rosa
ivan rosaFlag for United States of America

asked on

Make buttons required

Hi Folks,

I had created this simple form below, my question is how can i make it required to be filled if not input.
And for the select value how can i make it that IF, -select- is still not selected, make it also required?

Thanks for looking


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        function submitButton(frm){
            var form = document.forms.cvapplication;
			var output = '<p>Your submission has been accepted</p>';
            output += '<p>interests: ' + form.interests.value + '</p>';
            output += '<p>state: ' + form.country.value + '</p>';
            form.innerHTML = output;
            }
    </script>

</head>
<body>
        <form name="cvapplication" id="cvapplication">
            <p>Input Your Interests</p>
            <input type="text" name="interests" id="interests" size="40" style="font-style: oblique" required>

            <p>Input Your state</p>
            <select size="1" name="country" id="country" style="font-style: italic">
                    <option value="">- Select -</option>
                    <option value="US">United States</option>
                    <option value="CA">Canada</option>
            </select>

            <input type="button" onclick="submitButton(this.form)" value="Submit" >
        </form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Danilo Andrade
Danilo Andrade
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ivan rosa

ASKER

Dani, you nailed it first try.

I had thought about a creating a Object array to consolidate all statements,But then again wasn't really sure bout the function.., but they way you did it I have never seen it before, and I can see why you did it too, so the statements are a lot shorter...
I see what you did there my friend, very clever

By the way is it just me or it seems connecting XAML to C# or PowerShell is much easier as opposed creating JS..., I guess I'm making a big deal... hey on my defense this is my 3rd day where i'm connecting the 3 JS,CSS,and HTML... :)

Thanks so much!