Javascript 将值传递给php的弹出窗口
我正在尝试创建一个弹出窗口,其中包含输入的表单。有2个输入,在提交表单时,它应该从输入中获取值并将其分配给变量,然后将其传递给php代码。我所做的一切似乎都没有得到分配的值。我试着在javascript中输出变量,但当点击按钮时,它只是重置文本框Javascript 将值传递给php的弹出窗口,javascript,php,jquery,Javascript,Php,Jquery,我正在尝试创建一个弹出窗口,其中包含输入的表单。有2个输入,在提交表单时,它应该从输入中获取值并将其分配给变量,然后将其传递给php代码。我所做的一切似乎都没有得到分配的值。我试着在javascript中输出变量,但当点击按钮时,它只是重置文本框 <?php include'../dbconnect.php'; echo "in character creation"; if(isset($_POST['name']) && isset($_
<?php
include'../dbconnect.php';
echo "in character creation";
if(isset($_POST['name']) && isset($_POST['type']) ) {
$name = $_POST['name'];
$type = $_POST['type'];
echo $name." ".$type;
}
?>
<html>
<form id="frmNewChar">
Character Name: <input type="text" id="charName"></input> <br />
Character Type: <input type="text" id="charType" ></input> <br />
<button id="btnNewChar" >Submit</button>
</form>
</html>
<script language="JavaScript"><!--
$("#btnNewChar").click(function(){
var name = $("#charName").val;
var type = $("#charType").val;
$("#frmNewChar").before(name);
// $.post(this, {name: name, type: type}, function(data){
// text=data;
// elem = $("#frmNewChar");
delay=100;
// addTextByDelay(text,elem,delay);
// });
});
//--></script>
字符名:
字符类型:
提交
您的Jquery函数应该是这样的
$("#btnNewChar").click(function(){
var name = $("#charName").val();
var type = $("#charType").val();
$("#frmNewChar").before(name);
// $.post(this, {name: name, type: type}, function(data){
// text=data;
// elem = $("#frmNewChar");
delay=100;
// addTextByDelay(text,elem,delay);
// });
});
您使用了val而不是val()