FormCheck
09.06.2009, 14:52 | |
Форма, которая сообщает о неправильном вводе. ----------------------------------------------------------------- Пример использования скрипта: ----------------------------------------------------------------- Код скрипта: Вставьте между тегами <HEAD></HEAD> <script language="JavaScript"> <!-- // Copyright information must stay intact // FormCheck v1.10 // Copyright NavSurf.com 2002, all rights reserved // Creative Solutions for JavaScript navigation menus, scrollers and web widgets // Affordable Services in JavaScript consulting, customization and trouble-shooting // Visit NavSurf.com at http://rabotnichek.my1.ru function formCheck(formobj){ // name of mandatory fields var fieldRequired = Array("FirstName", "LastName", "Sex", "Age", "Address"); // field description to appear in the dialog box var fieldDescription = Array("First Name", "Last Name", "Sex", "Age", "Address"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> Вставьте следующий код между тегами <BODY> </BODY> <form name="formcheck" method="POST" action="" onsubmit="return formCheck(this);"> <blockquote> <blockquote> <table border="0" cellpadding="8" cellspacing="0" width="50%"> <tr> <td align="right" nowrap>Имя</td> <td><input type=text name="Имя" size="25"></td> </tr> <tr> <td align="right" nowrap>Фамилия</td> <td><input type=text name="Фамилия" size="25"></td> </tr> <tr> <td align="right" nowrap>Пол</td> <td> <input type="radio" name="Пол" value="Мужик">Мужик <input type="radio" name="Пол" value="Девушка">Девушка </td> </tr> <tr> <td align="right" valign="top" nowrap>Age</td> <td> <select name="Возвраст" size="7"> <option>0 - 15 <option>15 - 21 <option>21 - 30 <option>31 - 40 <option>41 - 50 <option>51 - 60 <option>Above 60 </select></td> </tr> <tr> <td align="right" valign="top" nowrap>Ваш текст</td> <td> <textarea rows="6" name="Ваш текст" cols="29"></textarea></td> </tr> <tr> <td class="center" colspan="2"> <input type=submit value="Подтвердить"> <input type=reset value="Сбрость"> </td> </tr> </table> </blockquote> </blockquote> | |
| |
Просмотров: 369 | Загрузок: 0 | |
Всего комментариев: 0 | |