Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

table row id passed to textfield 1

Status
Not open for further replies.

tinapa

Technical User
Nov 12, 2008
81
GB
hi guys!

do you have any ideas (using javascript) as to how i could pass the table row id to a textfield when i clicked a row in a table?

tnx for any ideas.
 
Here is an example of passing the id of a table row (tr) to a javascript function which prints the value of the id attribute into a textbox...

Code:
<html>
	<head>
        <style type="text/css">
			table,td,input{border-collapse:collapse;width:200px;font-family:Arial;font-size:10pt;border:1px solid #808080;}
		</style>
		
		<script type="text/javascript" language="javascript">
			function print_id(id){document.form.textbox.value=id;}
		</script> 
	</head>
	
	<body>
		<form name="form">
			<table>
				<tr id="tr-id-1" onClick="print_id(this.id)"><td>Row 1</td></tr>
				<tr id="tr-id-2" onClick="print_id(this.id)"><td>Row 2</td></tr>
				<tr id="tr-id-3" onClick="print_id(this.id)"><td>Row 3</td></tr>
				<tr id="tr-id-4" onClick="print_id(this.id)"><td>Row 4</td></tr>
				<tr id="tr-id-5" onClick="print_id(this.id)"><td>Row 5</td></tr>
				<tr id="tr-id-6" onClick="print_id(this.id)"><td>Row 6</td></tr>
				<tr id="tr-id-7" onClick="print_id(this.id)"><td>Row 7</td></tr>
			</table>
			
			<input type="text" id="textbox"></input>
		</form>
	</body>
</html>

Chris
 
thnx chris, that's perfect!!!

happy new year!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top