-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcome.html
More file actions
44 lines (44 loc) · 1.4 KB
/
Welcome.html
File metadata and controls
44 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<html>
<body>
<h1> Welcome </h1>
<iframe name="inputFrame" style="width:400px; height:250px; border:1px solid #ccc;">
<!-- Fallback for browsers that do not support iframes -->
<p>Your browser does not support iframes.</p>
</iframe>
<script>
// Dynamically write the form into the iframe
const frame = document.getElementsByName('inputFrame')[0];
frame.onload = function() {
const doc = frame.contentDocument || frame.contentWindow.document;
doc.open();
doc.write(`
<html><body>
<form id='userForm' onsubmit='return validateForm()' style="display:flex; flex-direction:column; gap:10px; margin:20px;">
<label>Name: <input type='text' id='name' name='name' required></label>
<label>Email: <input type='email' id='email' name='email' required></label>
<button type='submit'>Submit</button>
</form>
<script>
function validateForm() {
var name = document.getElementById('name').value.trim();
var email = document.getElementById('email').value.trim();
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!name) {
alert('Please enter your name.');
return false;
}
if (!emailPattern.test(email)) {
alert('Please enter a valid email address.');
return false;
}
alert('Form submitted successfully!');
return false; // Prevent actual submission for demo
}
<\/script>
</body></html>
`);
doc.close();
};
</script>
</body>
</html>