473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update data using jquery

semanticnotion
66 New Member
I have a page that lists records from a database call. I want to have an 'edit' link on each row that will popup a Jquery dialog so that the row can be edited. My question is how do I pass the data from the selected row to the jquery dialog box so that it can be edited?
i have the code which open jquery popup but the textboxes are empty.

Expand|Select|Wrap|Line Numbers
  1. <div id="boxes">
  2.  
  3. <div id="dialog2" class="window">
  4. <form method="post" action="update_books_a.php">
  5.   <input name="name" type="text" value="<?php echo $ing['book_name']; ?>"/><br/>
  6.   <input name="author" type="text" value="<?php echo $ing['author']; ?>"/>
  7.  
  8.     <input type="hidden" name="book_id" value="<?php print $ing['book_id'];?>" />
  9.     <br/><br/>
  10. <input type="submit" value="Update" class="close"/>
  11. </form>
  12. </div>
myphp code is
Expand|Select|Wrap|Line Numbers
  1. $select=mysql_query("select * from books where book_id='$book_id'") or die(mysql_error());
  2. while($ing=mysql_fetch_array($select))
  3. {
  4.  ?>
  5. <tr>
  6.     <td><a href="#dialog2" name="modal"><?php echo $ing['book_name'];?></a></td>
  7.     <td><?php echo $ing['author'];?></td></tr>
  8. <?php
  9. }
  10. ?>
and the java scipt is
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
  2. <script>
  3.  
  4. $(document).ready(function() {
  5.  
  6.     //select all the a tag with name equal to modal
  7.     $('a[name=modal]').click(function(e) {
  8.         //Cancel the link behavior
  9.         e.preventDefault();
  10.  
  11.         //Get the A tag
  12.         var id = $(this).attr('href');
  13.  
  14.         //Get the screen height and width
  15.         var maskHeight = $(document).height();
  16.         var maskWidth = $(window).width();
  17.  
  18.         //Set heigth and width to mask to fill up the whole screen
  19.         $('#mask').css({'width':maskWidth,'height':maskHeight});
  20.  
  21.         //transition effect
  22.         $('#mask').fadeIn(1000);
  23.         $('#mask').fadeTo("slow",0.8);
  24.  
  25.         //Get the window height and width
  26.         var winH = $(window).height();
  27.         var winW = $(window).width();
  28.  
  29.         //Set the popup window to center
  30.         $(id).css('top',  winH/2-$(id).height()/2);
  31.         $(id).css('left', winW/2-$(id).width()/2);
  32.  
  33.         //transition effect
  34.         $(id).fadeIn(2000);
  35.  
  36.     });
  37.  
  38.     //if close button is clicked
  39.     $('.window .close').click(function (e) {
  40.         //Cancel the link behavior
  41.         e.preventDefault();
  42.  
  43.         $('#mask').hide();
  44.         $('.window').hide();
  45.     });
  46.  
  47.     //if mask is clicked
  48.     $('#mask').click(function () {
  49.         $(this).hide();
  50.         $('.window').hide();
  51.     });
  52.  
  53. });
  54.  
  55. </script>
  56. <style type="text/css">
  57. body {
  58. font-family:verdana;
  59. font-size:15px;
  60. }
  61.  
  62. a {color:#333; text-decoration:none}
  63. a:hover {color:#ccc; text-decoration:none}
  64.  
  65. #mask {
  66.   position:absolute;
  67.   left:0;
  68.   top:0;
  69.   z-index:9000;
  70.   background-color:#000;
  71.   display:none;
  72. }
  73.  
  74. #boxes .window {
  75.   position:absolute;
  76.   left:0;
  77.   top:0;
  78.   width:440px;
  79.   height:200px;
  80.   display:none;
  81.   z-index:9999;
  82.   padding:20px;
  83. }
  84.  
  85.  
  86.  
  87. #boxes #dialog2 {
  88.   background:url(../images/notice.png) no-repeat 0 0 transparent;
  89.   width:326px;
  90.   height:229px;
  91.   padding:50px 0 20px 25px;
  92. }</style>
Dec 14 '10 #1
1 4330
Joseph Cobham
23 New Member
you could use jquery to execute the php script and return values to a named div for example

the html code
Expand|Select|Wrap|Line Numbers
  1. Bla Bla Bla Title <br />
  2. <div style="width:950px">
  3. <div style="float:left; width:450px">
  4. Your List of Book here
  5. <div id="dialog2" class="window">
  6. <form method="post" action="javascript: editBook();">
  7.   <input name="name" type="text" value="<?php echo $ing['book_name']; ?>"/><br/>
  8.   <input name="author" type="text" value="<?php echo $ing['author']; ?>"/>
  9.  
  10.     <input type="hidden" name="book_id" value="<?php print $ing['book_id'];?>" id="book_id" />
  11.     <br/><br/>
  12. <input type="submit" value="Update" class="close" onclick="javascript: editBook();"/>
  13. </form>
  14. </div>
  15.  
  16. <div style="float:left" id="showedit">
  17. <!--your edit will show here-->
  18. </div>
  19. </div>
Note the form action attribute value well as well as the div id showedit and the hidden form field id book_id. your html ends here...


Now time for the javascript function

Expand|Select|Wrap|Line Numbers
  1.     <script type="text/javascript" language="javascript">
  2.        function editBook(){
  3.     $("#showedit").html("Preparing Book Edit <br /><img src=\"images/load.gif\" />"); $.get("edit.php",{ cmd: "edit", b_id: $("#book_id").val() } ,function(data){  $("#showedit").html(data); });
  4.        }
  5.     </script>
your javascript ends here...

Now the php file named edit.php should be on the same directory as your current page...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include 'my_database_connection_file or settings.php';
  4.  
  5. $b_id = mysql_real_escape_string($get['b_id']);
  6.  
  7. $select=mysql_query("select * from books where book_id='$b_id'") or die(mysql_error());
  8. while($ing=mysql_fetch_array($select))
  9. {
  10.  ?>
  11. <tr>
  12.     <td><a href="#dialog2" name="modal"><?php echo $ing['book_name'];?></a></td>
  13.     <td><?php echo $ing['author'];?></td></tr>
  14. <?php
  15. }
  16. }
  17.  
  18. ?>
this should work without reloading the page and if you run into error please let me know.
Jan 18 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4229
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third underline. It was working fine before. ConnectionString in Web.config: ----------------------------------------- <?xml version="1.0"...
5
2028
by: jason | last post by:
Hi, all How can I update data (multiple rows, but not every rows) using dataset in datagrid? I mean is there any way I can let datagrid know which row(s)/column(s) has been modified and update them at database? Thanks.
0
1631
by: DC | last post by:
How can I update data using a Details view without using an AccessDataSource and its associated Insert, Update and Delete but using a DataReader instead?
2
3592
by: darrel | last post by:
I'm still struggling to find a javascript/ajax library that I want to stick with for a while. JQuery is looking great these days...refined, LOTS of plug-ins, and an active community. Is anyone using JQuery in their asp.net apps? Anyone know of any ASP.net jquery wrapper libraries to make development a bit faster? -Darrel
6
1507
werks
by: werks | last post by:
I have this code CoNN.BeginTrans CoNN.Execute "UPDATE tblsubject SET ='" & txtSubject1.Text & "', ='" & txtSubject2.Text & "', ='" & txtSubject3.Text & "', ='" & txtSubject4.Text & "', ='" & txtSubject5.Text & "', ='" & txtSubject6.Text & "', ='" & txtSubject7.Text & "', ='" & txtSubject8.Text & "' WHERE =" & v_ID & ";" CoNN.CommitTrans ...
10
7393
rizwan6feb
by: rizwan6feb | last post by:
Hi I have created a tabbed interface using jQuery using the code below <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> $(document).ready(function(){ $('#tabs').tabs({...
4
7264
by: pavanip | last post by:
Hi, I want to popup aspx page using jquery. I have written the following code <a href="Contactus.aspx?TB_iframe=true&height=250&width=200" class="thickbox" >AboutUs</a> I have called <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/thickbox.js"></script> <link rel="stylesheet"...
1
16946
by: progvar | last post by:
Hi i want to update data in database using datagridview actually i am displaying the data in datagridview and after that i want to update some rows data directly modifying the displayed data into the datagridview how can be done like this please send me some code or some help regards varinder sharma
25
5147
pradeepjain
by: pradeepjain | last post by:
<html> <head> <script src="jquery.js" type="text/javascript"></script> <script src="jquery.rating.js" type="text/javascript" language="javascript"></script> <link href="jquery.rating.css" type="text/css" rel="stylesheet"/> <link rel="stylesheet" type="text/css" href="style.css"> <script...
7
3650
by: HSXWillH | last post by:
I am designing an inventory system and am stuck on a potential problem. I have a table of Stock_Catalog containing the following fields: Stock_ID (random autonumber), Full_Desc, Serial, Auto, Mem, RC, Trans_Type. These are the basic item descriptions. I then have 5 other fields: Add (yes/no), MRR (yes/no), Qty, Unit_Price, Item_Note that...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.