Click here to Skip to main content
13,196,126 members (54,086 online)
Rate this:
 
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 2:21am
Updated 2-Sep-12 20: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
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171019.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2017
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