Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 2-Sep-12 20:40pm
v2

1 solution

I used table row click functon like below:
Link: http://www.tek-tips.com/viewthread.cfm?qid=1257692[^]
HTML
<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>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900