views:

50

answers:

1

Hello all,

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 'Contact not available'.

Any thoughts about how to go about doing this?

-Pritish.

A: 

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.

Am
Is there a way in which I can do this without involving id's ?The reason I say this is I've many such td elements in my table and there are hidden fields associated with each one of them.
Pritish
@Pritish, I've updated my entry to answer your question.
Am