Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta charset="utf-8" />
- <title>בדיקת טופס</title>
- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
- <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.2.0-rc2/css/bootstrap-rtl.min.css" rel="stylesheet">
- <script type="text/javascript">
- function CheckForm(form) {
- var errors = []; // מערך שגיאות
- var errorsDiv = document.getElementById('errors'); // בלוק שיחזיק את תוכן השגיאות
- var username = form.username; // שם משתמש
- var password = form.password; // סיסמא
- hide(errorsDiv); // העלמת הבלוק שמחזיק את השגיאות
- if (IsEmpty(username.value)) // אם שם המשתמש ריק
- errors.push('עליך להכניס שם משתמש!');
- if (IsEmpty(password.value)) // אם סיסמה ריקה
- errors.push('עליך להכניס סיסמה!');
- // ניתן להוסיף גם בדיקות כגון האם שם המשתמש מכיל רק אותיות באנגלית וכדומה
- if (errors.length) { // האם יש שגיאות במערך
- show(errorsDiv); // הצגת בלוק השגיאות
- errorsDiv.innerHTML = errors.join('<br />'); // הצגת השגיאות בבלוק המתאים
- return false;
- }
- // אם הגענו לכאן, כל הבדיקות עברו בהצלחה והטופס תקין. אפשר לעשות כרצונכם
- return true;
- }
- function show(x) { // הצגת אלמנט
- x.style.display = 'block';
- }
- function hide(x) { // העלמת אלמנט
- x.style.display = 'none';
- }
- function IsEmpty(s) { // הפונקציה מחזיקה האם s ריק
- return s == null || s.trim() == "";
- }
- </script>
- <style>
- * {
- outline: 0 !important;
- }
- .kobi_form {
- margin-top: 15px;
- }
- #errors {
- display: none;
- width: 412px;
- padding: 5px;
- margin-top: 10px;
- }
- </style>
- </head>
- <body dir="rtl">
- <div class="container">
- <form class="form-inline kobi_form" method="post" name="kobiForm" role="form" onsubmit="return CheckForm(this)">
- <div class="form-group">
- <label class="sr-only" for="username">שם משתמש:</label>
- <input type="text" class="form-control" name="username" id="username" placeholder="שם משתמש">
- </div>
- <div class="form-group">
- <label class="sr-only" for="pwd">סיסמה:</label>
- <input type="password" name="password" class="form-control" id="pwd" placeholder="סיסמה">
- </div>
- <button type="submit" class="btn btn-default">שלח</button>
- </form>
- <div id="errors" class="alert alert-warning"></div>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement