在表格中获取方法表单 [英] Get method form inside a table

查看:81
本文介绍了在表格中获取方法表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前提过一个问题,但我认为我没有正确地提出问题。
这是我的代码:

HTML

 < form method =GETid =demotestaction =#> 
< table id =contactustable>
< tr>
< td colspan =3>< h4>联络人表单:< / h4>< / td>
< / tr>
< tr>
< td width =15%>讯息< / td>
< td width =35%>< input type =textname =messageid =messageform =demotest>< / td>
< td width =7%>< span id =error-message>< / span>< / td>
< td colspan =2>< input type =submitname =submitid =submitvalue =submitonclick =return testingvalidation();形式= demotest > < / TD>
< td width =25%>< span id =status>讯息状态:< / span>< / td>
< / tr>
< / table>
< / form>

脚本

  function testingvalidation(){
var message = document.getElementById(message)。value;
var error = 0;

if(message ==){
var msg =请输入名称;
document.getElementById(error-message)。innerHTML = msg;
错误++;
}
else {
document.getElementById(error-message)。innerHTML =;
}

if(error> 0){
var msg =消息状态:错误;
document.getElementById(status)。innerHTML = msg;
返回false;
}
else {
messagesend =消息状态:发送;
document.getElementById(status)。innerHTML = messagesend;
返回true;






$ b这就是我的代码,但问题是,运行它,如果它通过验证成功..它会发送使用get方法的形式..但是消息不会出现在屏幕上(消息状态:发送)。如果我改变底部的返回true以返回false,则消息出现,但表单不会提交。



很抱歉,不断发表关于这个问题的新帖子。有人可以帮助我解决这个问题。谢谢

解决方案

脚本正常工作



你看不到消息,因为表单立即提交并加载一个新页面。新页面不包含该消息。


I have asked a question earlier on but I think I didn't ask the question correctly. This is my code:

HTML

<form method="GET" id="demotest" action="#">
    <table id="contactustable">
        <tr>
            <td colspan="3"><h4>Contact Form:</h4></td>
        </tr>
        <tr>
            <td width="15%">message </td>
            <td width="35%"><input type="text" name="message" id="message" form="demotest"></td>
            <td width="7%"><span id="error-message"></span></td>
            <td colspan="2"><input type="submit" name="submit" id="submit" value="submit" onclick="return testingvalidation();" form="demotest"> </td>
            <td width="25%"><span id="status">Message Status : </span></td>
        </tr>
    </table>
</form>

Script

function testingvalidation () {
    var message=document.getElementById("message").value;
    var error=0;

    if (message == "") {
        var msg="please enter name";
        document.getElementById("error-message").innerHTML=msg; 
        error++;
    }
    else {
        document.getElementById("error-message").innerHTML="";
    }

    if(error > 0) {
        var msg="Message Status : Error";
        document.getElementById("status").innerHTML=msg; 
        return false;
    }
    else {
        messagesend="Message Status : Send";
        document.getElementById("status").innerHTML=messagesend; 
        return true;
    }
}

Thats my code, bbut the problem is when ever i run it and if it goes pass the validation successfully.. it would send the form using the get method.. however the message wont come up on the screen ("Message Status: Send"). If i change the return true at the bottom to return false the message comes up but then the form wont submit.

Im sorry for keep making new posts about this problem. Can someone please help me to fix this issue. Thank You

解决方案

The script works fine.

You just can't see the message because the form immediately submits and loads a new page. The new page does not include the message.

这篇关于在表格中获取方法表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆