2013-10-21 56 views
0

我正在嘗試創建一個具有包含輸入的窗體的彈出窗口。有2個輸入,在提交表單時,應該從輸入中獲取值並將它們分配給變量,然後將其傳遞給php代碼。我做的任何事情似乎都沒有得到指定的值。香港專業教育學院嘗試在JavaScript中輸出變量,但是當按鈕被點擊彈出窗口,它將值傳遞給php

<?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> 

回答

0

你的jQuery函數應該是這樣的,它只是重置文本boxs,

$("#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()

相關問題