dsy1971 2016-10-20 10:20
浏览 32

未触发验证功能并提交表单

File with the code bellow is "newrecord.html" presents the form for submitting some record entries that suppose to do the a db and after the users submits the form the validation function is called to check with it's functions the user input. The form is loaded as normal but after the form is submitted the validation function is not being called and just redirects to to the "newRecord.php"

    <!DOCTYPE html>

<html>
    <head>
    <title>insert New Record</title>
    <style>
    .recordform {
border:1px solid #999999;
font: normal 14px helvetica;
color: #444444
}
</style>

    <script>
function validateAuthor(field)
{
return(field=="") ? "No Author Entered".
" : ""
}

function validateTitle(field)
{
return(field=="") ? "No Title Entered".
" : ""
}

function validateCategory(field)
{
return(field=="") ? "No Category Entered".
" : ""
}

function validateYear(field)
{
if (field=="") return "No Year Entered.
"
else if (field.length>4)
return "Enter Valid Year value (YYYY).
"
else if (/[^0-9]/.test(field))
return "Enter only numbers 0-9"
return ""
}

function validateIsbn(field)
{
if (field=="") return "No Isbn Entered.
"
else if (/[^0-9]/.test(field))
return "Enter only numbers"
return ""
}


function validate(form)
{
fail=validateAuthor(form.author.value)
fail+=validateTitle(form.title.value)
fail+=validateCategory(form.category.value)
fail+=validateYear(form.year.value)
fail+=validateIsbn(form.isbn.value)

if (fail==""){
    return true;
}else{
    alert(fail);
return false}
}

</script>


</head>
    <body>

<table border="0" cellpading="2" cellspacing="5" bgcolor="#eeeeee">
    <th colspan="2" align="center">Insert New Record</th>
    <form method="post" action="newRecord.php" onsubmit="return validate(this)">
    <tr><td>Author</td>
    <td><input type="text" maxlength="25" name="author"</td></tr>
    <tr><td>Title</td>
    <td><input type="text" maxlength="25" name="title"</td></tr>
    <tr><td>Category</td>
    <td><input type="text" maxlength="25" name="category"</td></tr>
    <tr><td>Year</td>
    <td><input type="text" maxlength="25" name="year"</td></tr>
    <tr><td>Isbn</td>
    <td><input type="text" maxlength="25" name="isbn"</td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Insert New Record"></td></tr>
</form>
    </table>
        </body>
            </html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看