开发者

Set HTML of td element as value of hidden field

I wanted to know how would I go about setting the HTML of my td element as the value of a hidden field.

<td align="center">
       <%if (inst_dm != null) {%>

    ...some code..
</td>
  <%} else {%>

<td align="center"> Contact not available.
   <%}%>
  <input type="hidden" name="inst_dmhidden" value="<%$(this).html().trim(); %>">

</td>

So, what I basically want is, in the input field inst_dmhidden, either the value from (..some code..) part or 'C开发者_开发知识库ontact not available'.

Any thoughts about how to go about doing this?

-Pritish.


Give your td and hidden element an id or a way to easily locate as I've done here

<td align="center" id="mytd">
     <%if (inst_dm != null) {%>

     ...some code..
</td>
  <%} else {%>

<td align="center" id="mytd"> Contact not available.
   <%}%>
  <input type="hidden" id="myhiddenfield" name="inst_dmhidden" value="<%$(this).html().trim(); %>">

</td>

Then using jQuery you could run this code:

$("#mytd").html($("#myhiddenfield").val());

UPDATE

In the case where you don't want to use IDs you could run some variant of this code :

$("td").each(function(index) {
    var td = $(this);
    td.html(td.find("input[type=hidden]").val());
});

The above code is assuming the hidden field is inside the td, but you can change that accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜