views:

29

answers:

3

How can I find the seq number given the id in this example?

<table>
<tr class="row_header thin_border"> 
    </tr><tr id="id33192010101533333"  seq="2">
    <td>20101015</td>
    <td>600</td>
    <td>730</td>        
    <td><a href="#" onclick="deleteActivity(3319,20101015,1);">Click</a></td>
    <td><a href="#" onclick='selectEditActivity("id3319201010153333");'>Click</a></td>
    </tr>

    <tr id="id3319201010151111"  seq="3">
    <td>20101015</td>
    <td>600</td>
    <td>730</td>        
    <td><a href="#" onclick="deleteActivity(3319,20101015,1);"> <img src="/bbhtml/img/deleteAction.png"></a></td>
    <td><a href="#" onclick='selectEditActivity("id3319201010151111");'><img src="/bbhtml/img/editAction.png"></a></td>
    </tr>
<table>


<script>
    function selectEditActivity(pass_id){
        alert("seq# =:" + ???)
    }
</script>
A: 

var id = document.getElementById("divId").getAttribute("id"); try this

change idand attribute id as yours

zod
A: 

You want to use objRef.getAttribute('seq') or plan old dot notation objRef.seq

epascarello
Property access like `objRef.seq` won't work for custom attributes since the HTML DOM has no mapping between them. (Except in IE<8 due to bugs.) This is the only time using `getAttribute` in an HTML document is actually the right thing. Although one could argue that custom attributes in general aren't the right thing.
bobince
@bobince Back it up with a jsbin and I will give you a cookie. I am not sure where you got that info from.
epascarello
http://jsbin.com/ojiyu4/2 — bof/undefined in all browsers except IE<9 (I lied about IE8! it's 9 where this is finally fixed) due to the aforementioned bug: IE doesn't understand the difference between attributes and properties, causing a wide-variety of well-known problems. In general DOM properties are a different thing to attributes and should not be confused: consider for example the difference between the `value` attribute (input default value) and the `value` property (current value).
bobince
A: 

Retrieve the DOM element and then get the seq attribute:

document.getElementById(id).getAttribute('seq'); // note: this will return a string, and getElementById might return null in case there is no element with the given id.
Ivo Wetzel
I am very close.... // this works alert(pass_id) // this works; var A = document.getElementById("id33192010101533333").getAttribute("seq"); alert(A); // but does not when I use the variable var B = document.getElementById(pass_id).getAttribute("seq"); alert(B);You may only edit a comment every 5 seconds.(click on this box to dismiss)
robert
Thanks this works.
robert