2016-12-06 7 views
0

にビューでフォームを検証することはできません:C:\ xamppの\ htdocsに\ AB-グループ\資産を\ JS \にDefault.jsCodeIgniterの - 私は、このリンクでファイルの.jsを持っているのJavaScriptファイル

私は、フォームを作りました私はそれを検証したい。私はすでにHTMLヘッドでjsファイルをリンクしていますが、動作しません。 私はcssファイルを呼び出すのと同じ方法を使用して成功しましたが、なぜjsファイルを呼び出せないのですか?

ここに私の見解コード:

<head> 
<title>Welcome to AB Group</title> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<link href="<?php echo base_url('assets/css/default.css')?>" 
    rel="stylesheet" type="text/css" /> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script src="<?php echo base_url(). "assets/js/default.js" ?>"></script> 

</head> 
<body> 
    <div class="form-style-3"> 
    <form id="form_sendEmail" name="form_sendEmail" method="post" onsubmit="validate();"> 
     <fieldset><legend>Personal</legend> 
      <label for="field1"><span>Name <span class="required">*</span></span><input type="text" class="input-field" name="name" id="name" value="" /></label> 
      <label for="field2"><span>Email <span class="required">*</span></span><input type="email" class="input-field" name="email" id="email" value="" /></label> 
      <label for="field3"><span>Phone <span class="required">*</span></span><input type="text" class="input-field" name="phone" id="phone" value="" /></label> 
      <label for="field4"><span>Subject</span><select name="field4" class="select-field"> 
       <option value="Information">Information</option> 
       <option value="Complain">Complain</option> 
       <option value="Other">Other</option> 
      </select></label> 
      <label for="field5"><span>Shipment Code <span class="optional"></span></span><input type="text" class="input-field" name="field5" value="" /></label> 
     </fieldset> 
     <fieldset><legend>Message</legend> 
      <label for="field6"><span>Message <span class="required">*</span></span><textarea name="message" id="message" class="textarea-field"></textarea></label> 
      <label><span>&nbsp;</span><input type="submit" onclick="validate()" id="sendEmail" value="Send Email" /></label> 
      <span class="required">* Indicates Required Field</span> 
     </fieldset> 
    </form> 
</div> 
</body> 

とここに私のjsファイル:

$(document).submit(function() { 
function validate() 
{ 
    var emailID = document.form_sendEmail.Email.value; 
    atpos = emailID.indexOf("@"); 
    dotpos = emailID.lastIndexOf("."); 

    if(document.form_sendEmail.Name.value == "") 
    { 
     alert("Please provide your name!"); 
     document.form_sendEmail.Name.focus() ; 
     return false; 
    } 

    if(document.form_sendEmail.Email.value == "") 
    { 
     alert("Please provide your Email!"); 
     document.form_sendEmail.Email.focus() ; 
     return false; 
    }else if(atpos < 1 || (dotpos - atpos < 2)) 
    { 
     alert("Please enter correct email ID") 
     document.form_sendEmail.EMail.focus() ; 
     return false; 
    } 

     if(document.form_sendEmail.Phone.value == "") 
    { 
     alert("Please provide your phone number!"); 
     document.form_sendEmail.Phone.focus() ; 
     return false; 
    } 

     if(document.form_sendEmail.Message.value == "") 
    { 
     alert("Please write your message!"); 
     document.form_sendEmail.Message.focus() ; 
     return false; 
    }else{ 
     return(true); 
    } 
} 
}); 

私は、JSファイルはフォームが空かないで検証し、同様のメールを確認でき願っています。私のコードで間違いを見つけるのを助けてください。どうもありがとうございました。

+0

'default.js'ファイルを取得しているかどうかを確認してください。 –

+0

はい、default.jsを取得します。 – anakpanti

答えて

0

私はそれが動作します(何とか)、その後$(document).ready(function()...になるとし$(document).submit(function()...を変更します。

0

jsファイルのリンク時に問題が発生している可能性があります。だからこれを試してください。

<script src="<?php echo base_url(); ?> assets/js/default.js"></script> 
+0

申し訳ありませんが、上記の回答として編集しましたが、それでも機能しません。 – anakpanti

+0

@anakpantiあなたが直面しているエラーはありますか? –

+0

閲覧してブラウザのコンソールで確認してください。問題がjsファイルにあれば、実際のエラーを見ることができます。また、この

関連する問題