2010-12-14 8 views
0

データベース呼び出しのレコードをリストするページがあります。私は行を編集できるようにJqueryダイアログをポップアップする各行に '編集'リンクを持っています。私の質問は、選択した行のデータをjqueryダイアログボックスに渡して編集できるようにする方法です。 jqueryポップアップを開くコードがありますが、テキストボックスは空です。jqueryを使用してデータを更新します。

<div id="boxes"> 

<div id="dialog2" class="window"> 
<form method="post" action="update_books_a.php"> 
    <input name="name" type="text" value="<?php echo $ing['book_name']; ?>"/>
<input name="author" type="text" value="<?php echo $ing['author']; ?>"/> <input type="hidden" name="book_id" value="<?php print $ing['book_id'];?>" />

<input type="submit" value="Update" class="close"/> </form> </div>

myphpコードjQueryのコードあなたは.text()方法を用いて各要素のテキスト値を抽出することができる




$(document).ready(function() { 

    //select all the a tag with name equal to modal 
    $('a[name=modal]').click(function(e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     //Get the A tag 
     var id = $(this).attr('href'); 

     //Get the screen height and width 
     var maskHeight = $(document).height(); 
     var maskWidth = $(window).width(); 

     //Set heigth and width to mask to fill up the whole screen 
     $('#mask').css({'width':maskWidth,'height':maskHeight}); 

     //transition effect 
     $('#mask').fadeIn(1000); 
     $('#mask').fadeTo("slow",0.8); 

     //Get the window height and width 
     var winH = $(window).height(); 
     var winW = $(window).width(); 

     //Set the popup window to center 
     $(id).css('top', winH/2-$(id).height()/2); 
     $(id).css('left', winW/2-$(id).width()/2); 

     //transition effect 
     $(id).fadeIn(2000); 

    }); 

    //if close button is clicked 
    $('.window .close').click(function (e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     $('#mask').hide(); 
     $('.window').hide(); 
    }); 

    //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
     $('.window').hide(); 
    }); 

}); 



body { 
font-family:verdana; 
font-size:15px; 
} 

a {color:#333; text-decoration:none} 
a:hover {color:#ccc; text-decoration:none} 

#mask { 
    position:absolute; 
    left:0; 
    top:0; 
    z-index:9000; 
    background-color:#000; 
    display:none; 
} 

#boxes .window { 
    position:absolute; 
    left:0; 
    top:0; 
    width:440px; 
    height:200px; 
    display:none; 
    z-index:9999; 
    padding:20px; 
} 



#boxes #dialog2 { 
    background:url(../images/notice.png) no-repeat 0 0 transparent; 
    width:326px; 
    height:229px; 
    padding:50px 0 20px 25px; 
}

答えて

0

ある

$select=mysql_query("select * from books where book_id='$book_id'") or die(mysql_error()); 
while($ing=mysql_fetch_array($select)) 
{ 
?> 
<tr> 
    <td><a href="#dialog2" name="modal"><?php echo $ing['book_name'];?></a></td> 
    <td><?php echo $ing['author'];?></td></tr> 

あります。あなたがhtmlの値が必要な場合は
あなたがテーブルにbook_idを持っていないので、私はあなたのために隠し入力を移入することはできません.html()またはyourNode.innerHTML

+0

そして '.valを使用してテキストボックスにそのテキストを貼り付け:

//Cancel the link behavior e.preventDefault(); 

は、このコードを追加します。 ) ' –

+0

newibi jqueryはここであなたのポイントを得ることができませんでした – hunter

0

を使用することができます。しかし、以下のコードは、book_nameとauthorのためにそれを行う方法を示しています。

あなたはこの行の後、あなたのクリックハンドラにコードを追加する必要があります(

// Copy book_name 
$("#dialog2 input[name=name]").val($(this).text()); 

// Copy author 
$("#dialog2 input[name=author]").val($(this).parent().next("td").text()); 
関連する問題