2011-11-02 79 views
0

我尝试使用tinybox Javascript。TinyBox窗体Bug

现在我会尝试使用它提交,但我不知道如何!?

<div id="add"> 
<form name="addVoc" action="javascript:TINY.box.show('system/import.php',1,300,150,1);" method="post" onsubmit='return checkForm();'> 
    <img src="images/gb.png" width="13px" height="8px"> English: <input type="text" name="English" class="addBox" /> 
    <img src="images/de.png" width="13px" height="8px"> German: <input type="text" name="German" class="addBoxD" /><br><br> 
    <img src="images/icon_hinweis.gif" width="10px" height="10px"> Add Voc <input type="submit" class="sbutton" value="Add"/> 
</form> 

现在它向我展示了tinybox,但没有任何反应,盒子是空的。

这是我的JS checkForm()

function checkForm(){ 

     if (document.forms["addVoc"].English.value==""){ 
      alert('Upps!'); 
      return false; 
     } 
     if (document.forms["addVoc"].German.value==""){ 
      alert('Upps!'); 
      return false; 
     } 
return true; 
    } 

在我的HTML的头,我挂迷你组合套件CSS和JS

<link rel="stylesheet" type="text/css" href="css/tinybox.css" /> 
<script type="text/javascript" src="js/tinybox.js"></script> 

这里是import.php:

<?php 
include 'include/connect.php'; 

$db_link = mysql_connect (MYSQL_HOST, MYSQL_BENUTZER, MYSQL_KENNWORT); 
if (!$db_link) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 

mysql_select_db("vokabel", $db_link); 

$sql="INSERT INTO word (Englisch, Deutsch) 
VALUES 
('$_POST[Englisch]','$_POST[Deutsch]')"; 

if (!mysql_query($sql,$db_link)) 
    { 
    die('Error: ' . mysql_error()); 
    } 
echo "Vokabel wurde hinzugefügt!"; 

mysql_close($db_link) 
?> 

我是新的JS,我希望有人能帮助我...没有tinybox它完美的作品

谢谢非常mutch

+0

请勿使用TinyBox。 它没有记录,源代码被混淆。 你会一直有麻烦 – John

回答

1

既然你有

<input type="text" name="Deutsch" class="addBoxD" /> 

我怀疑

if (document.forms["addVoc"].German.value==""){ 

应该读

if (document.forms["addVoc"].Deutsch.value==""){ 

此外,你应该添加

return true; 

checkForm()函数的最后一行。

我怀疑这些会解决你的小盒子问题 - 这很可能是因为system/import.php不输出任何东西。

在您的浏览器中加载system/import.php并确保获得您期望的输出。如果这样做,请确保system/import.php是正确的相对从当前页面到达import.php的路径。如果所有这些都是正确的,请编辑问题以包含import.php的源代码。

说了这么多的话,把这个小框称为action属性的形式确实有点奇怪 - 你是确定这就是你想要做的吗?你究竟想在这里完成什么?

编辑

试试这个:

HTML

<div id="add"> 
<form name="addVoc" action="javascript:void(0);" onsubmit="return checkForm();"> 
    <img src="images/gb.png" width="13px" height="8px"> Englisch: <input type="text" name="Englisch" class="addBox" /> 
    <img src="images/de.png" width="13px" height="8px"> Deutsch: <input type="text" name="Deutsch" class="addBoxD" /><br><br> 
    <img src="images/icon_hinweis.gif" width="10px" height="10px"> Add Voc <input type="submit" class="sbutton" value="Add"/> 
</form> 

的Javascript

function checkForm(){ 

    if (document.forms["addVoc"].Englisch.value=="") { 
     alert('Upps!'); 
     return false; 
    } 
    if (document.forms["addVoc"].Deutsch.value==""){ 
     alert('Upps!'); 
     return false; 
    } 

    TINY.box.show('system/import.php?Englisch='+document.forms["addVoc"].Englisch.value+'&Deutsch='+document.forms["addVoc"].Deutsch.value,1,300,150,1); 

    return false; 

} 

PHP

ANOTHER编辑

如果使用的是迷你组合套件2,改变这一行:

TINY.box.show('system/import.php?Englisch='+document.forms["addVoc"].Englisch.value+'&Deutsch='+document.forms["addVoc"].Deutsch.value,1,300,150,1); 

要这样:

TINY.box.show({url:'system/import.php',post:'Englisch='+document.forms["addVoc"].Englisch.value+'&Deutsch='+document.forms["addVoc"].Deutsch.value,width:300,height:150}); 

和更改两次出现$_GETimport.php$_POST

+0

啊sry我翻译成英文,因为我是德国人,我忘了其余的:-)但我补充说,返回真实;但没有任何反应,没有tinybox它完美的工作 - 我更新了我的问题中的代码,我尝试通过提交打开tinybox而不是一个新窗口 – Sebastian

+0

尝试编辑上面的代码:-D – DaveRandom

+0

:-(thx但它doesn不工作...我在谷歌搜索和有人说,我需要一个新的功能与Ajax ...但我不知道任何关于AJAX – Sebastian