Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Помогите не работает скрипт (https://javascript.ru/forum/misc/3163-pomogite-ne-rabotaet-skript.html)

MAX_NS 23.03.2009 20:54

Помогите не работает скрипт
 
Два скрипта у меня стоят на странице первый проверяет количество введёных символов для textarea второй заполнение текстовых полей

Всё это работает в Фаер фокс но не работает в IE

Как я понял IE ругается на

строку в первом коде

document.getElementById(ide).innerHTML = limit_text;

И строку во втором коде

document.getElementById("alert").innerHTML = "";

IE выдаёт ошибку


Code: 0
Error Message: Неизвестная ошибка выполнения

Как заставить работать скрипты под IE?


<script type="text/javascript">

   var ns6=document.getElementById&&!document.all
      function restrictinput(maxlength, e, placeholder)
      {if (window.event && event.srcElement.value.length >= maxlength)
         return false;
      else if (e.target && e.target == eval(placeholder) && e.target.value.length >= maxlength)
         {
         var pressedkey = /[a-zA-Z0-9\.\,\/]/;
         if (pressedkey.test(String.fromCharCode(e.which)))
            e.stopPropagation();
         }
      }

   function countlimit(maxlength, e, placeholder)
           {
      var theform = eval(placeholder);
      var lengthleft = maxlength-theform.value.length;
      var placeholderobj = document.all ? document.all[placeholder] : document.getElementById(placeholder);
      if (window.event || e.target&&e.target == eval(placeholder))
             {
         if (lengthleft < 0)
             theform.value = theform.value.substring(0, maxlength);
         placeholderobj.innerHTML = lengthleft
             }
           }

   function displaylimit(thename, theid, thelimit, ide)
           {
      var theform = theid != "" ? document.getElementById(theid) : thename;
      var limit_text = 'ìîæíî ââåñòè <span id="' + theform.toString() + '">' + thelimit + '</span> ñèìâîëîâ';
      if (document.all || ns6)
           document.getElementById(ide).innerHTML = limit_text;



      if (document.all)
             {
         eval(theform).onkeypress = function(){ return restrictinput(thelimit, event, theform)}
         eval(theform).onkeyup = function(){ countlimit(thelimit, event, theform)}
              }
      else if (ns6)
             {
         document.body.addEventListener('keypress', function(event) { restrictinput(thelimit, event, theform) }, true);
         document.body.addEventListener('keyup', function(event) { countlimit(thelimit, event, theform) }, true);
             }
            }

    displaylimit("document.preview.skills", "", 300, "skills");
    displaylimit("document.preview.finres", "", 300, "finres");
    displaylimit("document.preview.matres", "", 400, "matres");
    displaylimit("document.preview.offers", "", 400, "offers");

</script>





<script type="text/javascript">


	function text (str) { return /[0-9_;:'!~?=+<|>]/g.test(str); }
    function text2 (str) { return /^[_;:'!~?=+<|>]/g.test(str); }
   function numeric (str) { return /^[0-9-\+\(\)\s]+z/.test(str + "z"); }


   function mail (str) { return /^[a-z0-9_\.]+@[a-z0-9_\.]+.[a-z]{2,3}$/.test(str); }

   function checkForm ()
      {
      var title;
      var elem;
      var dutyField = "Íå çàïîëíåíî ïîëå ";
      var wrongField = "Íåêîðåêòíîå çíà÷åíèå ïîëÿ ";
      var check = true;




      function checkError (field, str)
         {
         document.getElementById("alert").innerHTML = str;
         document.forms.preview.field.focus();
         check = false;
         }

      document.getElementById("alert").innerHTML = "";



      if (check)
         {
         title = '"Ô.È.Î"';
         elem = document.preview.name.value;
         if (elem.length == 0) checkError('name', dutyField + title);
         else if (text(elem)) checkError('name', wrongField + title);
         }

      if (check)
         {
         title = '"Íèê â ñåòè"';
         elem = document.preview.nikname.value;
         if (elem.length == 0) checkError('nikname', dutyField + title);
         else if (text2(elem)) checkError('nikname', wrongField + title);
         }

         if (check)
         {
          title = '"Ïîë"';
         elem = document.preview.floor.value;
         if (elem == 'íåóêàçàí') checkError('floor', dutyField + title);
         }

         if (check)
         {
         title = '"Äåíü ðîæäåíèÿ"';
         elem = document.preview.day.value;
         if (elem.length == 0) checkError('day', dutyField + title);
         else if (!numeric(elem)) checkError('day', wrongField + title);
         }



         if (check)
         {
          title = '"Ìåñÿö ðîæäåíèÿ"';
         elem = document.preview.month.value;
         if (elem == 'íåóêàçàí') checkError('month', dutyField + title);
         }

      if (check)
         {
         title = '"Ãîä ðîæäåíèÿ"';
         elem = document.preview.age.value;
         if (elem.length == 0) checkError('age', dutyField + title);
         else if (!numeric(elem)) checkError('age', wrongField + title);
         }

      if (check)
         {
         title = '"Ìåñòî æèòåëüñòâà"';
         elem = document.preview.residence.value;
         if (elem.length == 0) checkError('residence', dutyField + title);
         else if (text(elem)) checkError('residence', wrongField + title);
         }



      if (check)
         {
         title = '"E-mail"';
         elem = document.preview.email.value;
         if (elem.length == 0) checkError('email', dutyField + title);
         else if (!mail(elem)) checkError('email', wrongField + title);
         }



      if (check)  { document.preview.submit(); }

      return check;
      }
</script>

evgen28 24.03.2009 16:02

ie какой версии?

MAX_NS 24.03.2009 16:25

Как можно вообще адаптировать под все IE браузеры этот код?
Проверял работоспособность на IE 7.0.6

Или может кто подскажет более работоспособный ява скрипт работающий со всеми браузерами.

Мне надо проверять заполненность полей анкеты и количество вводимых в textarea символов


Часовой пояс GMT +3, время: 10:32.