0

JavaScriptで動的フォームを作成しています。JavaScriptからサーブレットにデータを送信したい。フォームで送信ボタンを使用しません。ボタンのみを使用して、データを送信します。誰か助けてください。

これは私のコードです:

var myform=document.createElement("form");
myform.setAttribute("id", "myform");

var tname=document.createElement('input');
tname.setAttribute('type','text');
tname.setAttribute('name', "name");

var leaveMessage=document.createElement('input');
leaveMessage.setAttribute('type','button');
leaveMessage.setAttribute('name', "msgButton");
leaveMessage.setAttribute('value', "Leave Message");

myform.appendChild(tname);
myform.appendChild(leaveMessage);

document.body.appendChild(myform);
4

1 に答える 1

0

いくつかのステートメントも追加します

var myform=document.createElement("form");
myform.setAttribute("id", "myform");
myform.setAttribute('action', "/mypage");
myform.setAttribute('method', "post");

var tname=document.createElement('input');
tname.setAttribute('type','text');
tname.setAttribute('name', "name");
var leaveMessage=document.createElement('input');
leaveMessage.setAttribute('type','button');
leaveMessage.setAttribute('name', "msgButton");
leaveMessage.setAttribute('value', "Leave Message");

myform.appendChild(tname);
myform.appendChild(leaveMessage);

document.body.appendChild(myform);

document.forms["myform"].submit();
于 2012-07-24T07:30:53.750 に答える