我試圖提交使用JavaScript函數的形式,下面將我的javascript功能從形式如何獲取值使用javascript
function submit_form(id_textarea,image_name_IN){
//var value_filled_textbox=document.getElementById(textarea_id_in).value;
var form=document.createElement("form_temp");//temporary dummy form
form.setAttribute("method","post");//its a post method
form.setAttribute("action","comment.php"); // to which the page needs to be submitted
var comment_value=document.getElementById(id_textarea).value; // gets the content of textarea
// alert(comment_value);// just to make sure that you are getting the commeted text area content
//create a hidden field for comments text
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "comment_content");
hiddenField.setAttribute("value", comment_value);
form.appendChild(hiddenField);
// create a hidden field for passing image name
var hiddenField2 = document.createElement("input");
hiddenField2.setAttribute("type", "hidden");
hiddenField2.setAttribute("name", "image_name");
hiddenField2.setAttribute("value",image_name_IN);
form.appendChild(hiddenField2);
document.body.appendChild(form);
form.submit();
//alert(value_filled_textbox);
window.open("http://127.0.0.1/comment.php");
//document.getElementById('myform').submit();
}
同時發佈評論, 我得到兩個註釋公佈。 php窗口,其中一個帶有結果,另一個帶有兩個警告,說未定義的值「image_name」和「comment_content」
你得到了什麼錯誤? –
使用jQuery提交http://api.jquery.com/submit/提交表單。 –
*什麼*不是功能? – CodingIntrigue