zoit zoit - 4 months ago 8
Javascript Question

Retrieving data from span with jquery and c#

I'm trying to retrieve some values from span which are inside a td. I have this function:

function reorder() {
alert("Entrando en reorder");
strorder = "";
var totalid = $('#ctl00_ContentPlaceHolder1_grdResultados tr td input').length;
alert(totalid);
for (var i = 0; i < totalid; i++) {
strorder = strorder +$('#ctl00_ContentPlaceHolder1_grdResultados tr td span')[i].text()+"*"+ $('#ctl00_ContentPlaceHolder1_grdResultados tr td input')[i].getAttribute("value") + "|";
alert("strorder1");
}
//strorder = window.location.href;
alert("strorder2");
}


And the source code is this (a piece of the code):

<table class="table table-hover tablaDimensiones" cellspacing="0" border="0" id="ctl00_ContentPlaceHolder1_grdResultados" style="border-collapse:collapse;">
<tr>
<th scope="col">
<a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados&#39;,&#39;Sort$titulo&#39;)">Título</a>
</th>
<th scope="col">Opciones</th>
</tr>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_lblTitulo">Dimension1</span>
<input type="hidden" name="ctl00$ContentPlaceHolder1$grdResultados$ctl02$hdnid" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_hdnid" value="1" />
</td>
<td>
<a id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEditar" title="Editar" class="btn btn-default" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEditar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</a>
&nbsp;
<a onclick="return confirm(&#39;¿Desea elimnar la dimensión?&#39;);" id="ctl00_ContentPlaceHolder1_grdResultados_ctl02_cmdEliminar" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$grdResultados$ctl02$cmdEliminar&#39;,&#39;&#39;)">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>

</td>
</tr>
<tr>


How can I do it?, because in this way I don't have what I want. Regards

Answer

This may be optimistic

 $td = $('.tablaDimensiones tr td');

        var spans = $td.find('span');
        var inps = $td.find('input');

        var len = spans.length;

        var sortorder = "";

        for (var i = 0; i < len; i++) {
            sortorder += spans.eq(i).text() + "*" + inps.eq(i).text() + "|";             
        }