1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Document</ title >
7+
8+ </ head >
9+ < body >
10+
11+
12+
13+
14+
15+ < h1 > Form</ h1 >
16+
17+ < form id ="userForm " onsubmit ="handleSubmit(event) ">
18+ < label for ="name "> Name</ label >
19+ < input type ="text " id ="name " placeholder ="Enter Your name " required > < br > < br >
20+
21+
22+ < label for ="email "> Email</ label >
23+ < input type ="email " id ="email " placeholder ="Enter Email " required > < br > < br >
24+
25+ < label for ="phone "> Phone Number</ label >
26+ < input type ="tel " id ="phone " placeholder ="Enter Phone number " required > < br > < br >
27+
28+ < label for ="address "> Address</ label >
29+ < input type ="text " id ="address " placeholder ="Enter Address " required > < br > < br >
30+
31+ < label > Gender</ label >
32+ < div class ="gender-options ">
33+ < label > < input type ="radio " name ="gender " value ="Male " required > Male</ label >
34+ < label > < input type ="radio " name ="gender " value ="Female "> Female</ label >
35+ </ div >
36+
37+ < label for ="course "> Course</ label > < br >
38+ < select id ="course " required >
39+ < option value =""> --Select Course--</ option > < br > < br >
40+ < option value ="Web Development "> Web Development</ option >
41+ < option value ="Data Science "> Data Science</ option >
42+ </ select >
43+ < br > < br >
44+
45+ < button type ="submit "> Submit</ button >
46+ </ form >
47+
48+ < div class ="output " id ="output "> </ div >
49+
50+ < script >
51+ function handleSubmit ( event ) {
52+ event . preventDefault ( ) ;
53+
54+ const name = document . getElementById ( 'name' ) . value ;
55+ const email = document . getElementById ( 'email' ) . value ;
56+ const phone = document . getElementById ( 'phone' ) . value ;
57+ const address = document . getElementById ( 'address' ) . value ;
58+ const gender = document . querySelector ( 'input[name="gender"]:checked' ) ?. value || '' ;
59+ const course = document . getElementById ( 'course' ) . value ;
60+
61+ const output = document . getElementById ( 'output' ) ;
62+ output . innerHTML = `
63+ <h3>Submitted Data</h3>
64+ <p><strong>Name:</strong> ${ name } </p>
65+ <p><strong>Email:</strong> ${ email } </p>
66+ <p><strong>Phone:</strong> ${ phone } </p>
67+ <p><strong>Address:</strong> ${ address } </p>
68+ <p><strong>Gender:</strong> ${ gender } </p>
69+ <p><strong>Course:</strong> ${ course } </p>
70+ ` ;
71+
72+ event . target . reset ( ) ;
73+ }
74+ </ script >
75+
76+
77+
78+
79+
80+ </ body >
81+ </ html >
0 commit comments