473,545 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onclick event for table row record to form field

27 New Member
hello,
Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function select_cell(obj)
  3. {
  4.  
  5.     document.getElementById('complaint').value = obj.innerText;
  6.     document.getElementById('selected_form');
  7. }
[PHP]echo "<tr><th>Compla int</th>";
while ($comp_rec= mysql_fetch_arr ay($complaintTa ble))
{echo "<tr><td id = 'complaint' onclick='select _cell(this);'>" ; echo $comp_rec['complaint'];
echo "</td>";[/PHP]

[HTML]<table id = "MAINFORM">
<form id = "selected_f orm" name = "complaint_sett ings" method = "POST" action = "php_complaint_ mysql.php">
<td>
<table border = "3" bordercolor = "gold" bgcolor = "00008B">
<tr><td>
<p style = "color:gold">Co mplaint: <br>
<input type = "text" size = "50" maxlength = "50" name = "complaint" >
</td></tr><br>
<tr><td>
<input type = "submit" name = "submit_c" value = "submit"> <br>
<input type = "submit" name = "submit_c" value = "update"> <br>
<input type = "submit" name = "submit_c" value = "delete" onClick = "return confirm('Are you sure you want to delete record?')">[/HTML]

my problem now is how to pass along my primary key which is the unique id of each $comp_rec to my form as a hidden variable so i can pass $_POST['complaint'] to php_complaint_m ysql.php for update or delete. As it is now the table i use onclick only shows a single column(complain t) and even if i add another cell/column (id) the two cells are not carried and placed in separate fields on the same form. Any idea on populating form fields by clicking a row record with each attribute being passed to appropriate field? Attribute ID not presently on table. wish to keep hidden. But need to pass ID so i can use to update mysql.
thanks.
Jul 12 '07 #1
4 20027
prosad
27 New Member
hi all, struggling with javascript, need help please!
i have a table being generated from a MySQL DB and wish to enable onclick on table row so that table data on that row can be transferred to a form for update or delete. the table row contains the primary key ($comp_rec['id']) which will be used to reference data ($comp_rec['complaint']) in DB for update or delete. my codes are as follows:

1. Javascript Function:

function select_cell(obj )
Expand|Select|Wrap|Line Numbers
  1. {
  2.     document.getElementById('complaint').value = obj.cells[0].innerText;
  3.     document.getElementById('complaint').value = obj.cells[1].innerText;
  4.     document.getElementById('selected_form');
2. Table generated from MyQL using PHP:

[PHP]echo "<table>";
echo "<td><div>" ;"</div></td>";
echo "<table id = \"table_c\" border = \"4\" bordercolor = 00008B>";
echo "<tr><th>Compla int</th>";
while ($comp_rec= mysql_fetch_arr ay($complaintTa ble))
{echo "<tr id = 'complaint' onclick='select _cell(this);'>< td> "; echo $comp_rec['complaint'];
echo "</td>"; echo "<td>"; echo $comp_rec['id']; echo "</td>";

}
echo "</tr></table>";[/PHP]

3. HTML Form table row data supposed to be transfered to. Primary id to be sent to hidden field. if i set id value to a primary key e.g. "1" i can update without problem but that will mean putting the onclick into the <td> tag. i wish instead to use the onclick in the <tr> tag.

[HTML]<table id = "MAINFORM">
<form id = "selected_f orm" name = "complaint_sett ings" method = "POST" action = "php_complaint_ mysql.php">
<td>
<table border = "3" bordercolor = "gold" bgcolor = "00008B">
<tr><td>
<p style = "color:gold">Co mplaint: <br>
<input type = "text" size = "50" maxlength = "50" name = "complaint" value = "">
</td></tr><br>
<INPUT TYPE="hidden" NAME="id" value="">
<tr><td>
<input type = "submit" name = "submit_c" value = "submit"> <br>
<input type = "submit" name = "submit_c" value = "update"> <br>
<input type = "submit" name = "submit_c" value = "delete" onClick = "return confirm('Are you sure you want to delete record?')">

</td></tr>
<br><br>
</table>
</form>[/HTML]

looking forward to speedy response.
Jul 23 '07 #2
JosAH
11,448 Recognized Expert MVP
Your question is a Javascript question; this is a Java forum; Java and Javascript
are completely disjunct and different. Do you want me to move your question to
a Javascript forum where your question can be better answered?

kind regards,

Jos
Jul 23 '07 #3
prosad
27 New Member
Your question is a Javascript question; this is a Java forum; Java and Javascript
are completely disjunct and different. Do you want me to move your question to
a Javascript forum where your question can be better answered?

kind regards,

Jos
yes please, my mistake. apologies.
Jul 23 '07 #4
JosAH
11,448 Recognized Expert MVP
yes please, my mistake. apologies.
Consider it done; best of luck. (no need to apologize)

kind regards,

Jos
Jul 23 '07 #5

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

Similar topics

4
4280
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field that has been modified/clicked the form doesn't always submit. When it does work, a Stored procedure is passed form variables and updates to the db...
2
7026
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick and onChange handlers do some minor manipulation of form data (although they work on different form elements). If the onChange event fires, I need...
5
6769
by: Wouter | last post by:
Hi, I had a javscript what does the follow. When a checkbox is yes then i will see a form field. When a checkbox is no i dont see the form field. Can somehelp me for that script ? Greets Wouter
2
3395
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick event of the button. Things work fine if you move from one field to another using tab keys. But if you change something in the first text box and move...
9
3317
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text field called . It gets populated based on what the user selects in a field on the sub form (code in the AfterUpdate Event). Here's the issue. If the user deletes a subform record. The field on the main form shows null even if...
2
4329
by: Mike | last post by:
I'm sure this has been covered before in the newsgroup but have had no luck locating it. I have two tables: InstMonitors & MonModDesc Structure of MonModDesc: Model, Description Structure of InstMonitors: CompName, Make, Model, Description, Serial, PurchDate, WarrExpDate
4
4786
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants opens up with the record that corresponds to the one on the cont. form. I put that same code for the OnClick of an image control (i.e. the user...
21
13422
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have an explanation? Is this evidence of corruption, or a known side effect? TIA Bruce
2
2738
by: DavidGeorge | last post by:
In an earlier thread I recounted a problem I was having, but it took a while to reduce the problem to it's basic components and the issue became somewhat confused in reaching that point. I hope you will excuse me for bringing it up again but this issue is very frustrating. I created a new form in a brand new (Access 2003) database. This...
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
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
7923
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...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
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
4960
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
3466
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...
1
1901
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

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.