Reputation: 1
I'm having difficulty in using a variable derived from Javascript into an ASP tag .
<script language="javascript">
if (arg)
{
var text_box_to_fill = arg.sendValue_Code;
document.getElementById( document.getElementById("<%= "+text_box_to_fill+".clientID %>").value = selected_libelle_value;
}
</script>
Any suggestions?
Upvotes: 0
Views: 120
Reputation: 50728
Not sure why there are duplicate "document.getElementById" code references, but you can only go from server to client in this fashion. So it would be:
<script language="javascript">
if (arg)
{
var text_box_to_fill = arg.sendValue_Code;
document.getElementById("<%= text_box_to_fill.ClientID %>").value = selected_libelle_value;
}
</script>
EDIT: Note that you have to have the script in the same page or control as the origin of "text_box_to_fill". If you have this script in a page, and the textbox is in the user control, that won't work.
Upvotes: 1
Reputation: 236
text_box_to_fill
is defined client side in the browser, whereas the <% %> tags are evaluated on the server. It's not possible to reference javascript variables from the server code.
Upvotes: 0