0

POSTを受信するためのコードは次のとおりです。

{{velocity}}
#if ($request.getMethod() == "POST")
$request.getParameter("servicename")
#end
{{/velocity}}

POSTを送信するコードは次のとおりです。

{{velocity}}

{{html}}

javascriptのコードは次のとおりです。

<script type="text/javascript">
function validateForm()
{

c = confirm("Are you sure ?");
if(c == true){
alert("The foo has been created");
}else{
alert("The foo creation has been canceled.");
return false;
}
}
</script>

htmlフォームのコードは次のとおりです。

<form name="myForm" action="$doc.getURL('view')" method="post" onsubmit="return  validateForm()">
<input type="hidden" name="xaction" value="createservice" />
 Foo Name:
<input type="text" name="servicename" />
 <input type="submit" value="Create" />
 </form>
{{/html}}

 {{/velocity}}
4

1 に答える 1

1

これが役立つかどうかはわかりませんが、次のコードが機能します。

<html>
<head>
<script type="text/javascript">

function foo() {
    if (confirm("Are you sure?")) {
        alert("OK");
        return true;
    }
    else {
        alert("KO");
        return false;
    }
}

</script>
</head>
<body>

<form method="post" onsubmit="return foo()">
    <input type="text" />
    <input type="submit" value="Go" />
</form>

</body>
</html>

そして、あなたは取り除くことができますfoo

<form method="post" onsubmit="return confirm('Are you sure?')">
于 2011-11-08T14:02:41.480 に答える