onSubmit表单从另一个文件夹调用外部javascript文件



我想调用一个外部javascript文件,该文件位于特定表单的另一个文件夹中。当我将javascript代码保存在表单的文件中时,javascript会完美地执行。但我为此创建了另一个javascript文件,我想将其调用到我的表单中

你能告诉我如何更改我的代码吗接受任何建议

形成

 <form id = "additems" action="../cms/insert.php" onsubmit="return allnumeric(price,stock)" enctype="multipart/form-data" method="post" />
        <div id="formContents">
          <label for="title">Title of your product:
          <div id="formContents"> </label><input type="text" name="title" style="width: 180px"  /><p>
          </div>
              <div id="formContents">
          <label for="description">Description of your product:
          <div id="formContents"> </label><input type="text" name="description" style="width: 180px" onfocus="if(this.value==this.defaultValue)this.value=''"    
                onblur="if(this.value=='')this.value=this.defaultValue" 
                value=" description of the product" maxlength="19" /><p>
          </div>
          <label for="price">Price:      &pound;    </label><input type="INT" name="price" style="width: 40px" /><p>
          <label for="stock">Quantity:</label><input type="text" name="stock" style="width: 40px" />

validate.js

<script>
{
var x=document.forms["additems"]["title"].value;
if (x==null || x=="")
  {
  alert("Please fill out the TITLE of your product");
  return false;
  }
var y=document.forms["additems"]["price"].value;
if (y==null || y=="")
  {
  alert("Please fill out the PRICE of your product");
  return false;
  }
var z=document.forms["additems"]["stock"].value;
if (z==null || z=="")
  {
  alert("Please fill out the QUANTITY of your product");
  return false;
  }
}
function allnumeric(price,stock)  
   {  
   validateForm();
      var numbers = /^[0-9]+$/;  
      if(!price.value.match(numbers))   
          {  
          alert('PRICE--Please input numeric characters only');  
          return false;  
          }
      else if(!stock.value.match(numbers))
            {  
                alert('STOCk--Please input numeric characters only');  
                return false;  
            }    
   }  
</script>

您有在表单文件中加载javascript文件的调用吗?

<head>标签中,您应该有以下内容:

<script type="text/javascript" src="somefile.js"></script>

如果somefile.js不在同一目录中,则需要在它们前面添加一个相对路径。

最新更新