javascript - script that checks text field do not work with chrome -


i have form , java script checks if text filed not empty. problem is, code works ie , firefox not work chrome.

<form action="editor.php?id=<?=$id_book?>" method="post" name="form1" onsubmit="return check_form(this)" >   <script language="javascript">     function check()     {       if ((document.all.title.value==""))       {          alert("Отсутствует название книги!");        }        if ((document.all.price.value==""))       {         alert("Отсутствует цена книги!");        }        if ((document.all.descrip.value==""))       {          alert("Отсутствует описание книги!");        }       else       {         document.all.form1.submit();       }     }   </script>   <div class="list-group">      <div class="input-group input-group-lg">       <span class="input-group-addon"><div class="inp_width">Название:</div></span>       <input type="text" name="title" class="form-control" value="<?=$value['title']?>">     </div><br />        <div class="input-group input-group-lg">       <span class="input-group-addon"><div class="inp_width">Цена:</div></span>       <input type="text" name="price" class="form-control" value="<?=$value['price']?>">     </div><br />      <div class="input-group input-group-lg">       <span class="input-group-addon"><div class="inp_width">Описание</div></span>              <textarea type="text" name="descrip" class="myform-control"  rows="5"><?=$value['descrip']?></textarea>     </div><br />      <?php endforeach; ?>      <div class="col-md-12">       <div class="col-md-2"><button type="button" value="submit" class="btn btn-primary" onclick="check()">Редактировать</button>    </form>  </div> 

any ideas? more problem if have 1 filed check in chrome, scripts works fine. submit button not work if need check several fields.

update: sorry guys... works fine... copy-paste kill me... type button should "submit" instead of "button"... next time i'll should more careful coping code:)

your if statements incorrect. last if statement stop submit happening, call "else" step associated with. javascript please try following format:

if (condition1)   {    code executed if condition1 true   } else if (condition2)   {   code executed if condition2 true   } else   {   code executed if neither condition1 nor condition2 true   } 

additionally, if want check multiple values , if of values don't exist should try sort of flag. example:

if (document.all.title.value==""){     message += "title missing"; } if (document.all.price.value==""){     message += "price missing"; }  if (message == ""){      document.all.form1.submit(); }else{     alert(message) } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -