Click here to Skip to main content
11,480,148 members (68,163 online)
Rate this: bad
good
Please Sign up or sign in to vote.
Hi all...
How should we identify or find value of a control when there are many controls in javascript?
How should identify value of a row entries in table in javascript?
I'm working on MVC3. In my project I have used an action link on which i'm showing modal popup. In that pop up i'm getting data of multiple users(eg. jack,sachin) in table like structure.
Now on my view I've textboxfor(with id="txtOne") and i used an action link(with url text string "select" for each user at the end of row like we do have for edit/delete in grid view at the end). now whenever i select a user his first name should appear in text box. So what to do for this.
How should we identify or find value of a control in javascript?
Thanks in advance...
Posted 31-Aug-12 3:21am
Edited 2-Sep-12 21:40pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I used table row click functon like below:
Link: http://www.tek-tips.com/viewthread.cfm?qid=1257692[^]
 
<html>
<head>
    <title>Untitled</title>
 
<script type="text/javascript"><!--
 
function getVal(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
 
    alert(targ.innerHTML);
}
 
onload = function() {
    var t = document.getElementById("main").getElementsByTagName("td");
    for ( var i = 0; i < t.length; i++ )
        t[i].onclick = getVal;
}
 
//--></script>
    
<style type="text/css">
 
#main td {
    border: 1px solid gray;
}
 
</style>
</head>
 
<body>
 
<table id="main"><tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
</tr><tr>
    <td>5</td>
    <td>6</td>
    <td>7</td>
    <td>8</td>
</tr><tr>
    <td>9</td>
    <td>10</td>
    <td>11</td>
    <td>12</td>
</tr></table>
 
</body>
</html>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 235
1 Sergey Alexandrovich Kryukov 215
2 Richard MacCutchan 100
3 F-ES Sitecore 75
4 DamithSL 65
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100