views:

121

answers:

2

Hi, I want to ask if there is a way to insert variable inside another string which is part of another statement. For example:

function SomeFunction(field) {  

  var someVariable = document.getElementById('<%=' + field + '.ClientID %>');
}

But I've got an error:

Error   6   'string' does not contain a definition for 'ClientID'

Thank you.

A: 

You can not get a value from server-side tags, this won't work:

<%=' + field + '.ClientID %>

You need to do it some way so you only do this:

var someVariable = document.getElementById(field);
Sarfraz
A: 

Assuming field is say 'name' and you give id to name field as "name.4" where 4 is ClientID.

function SomeFunction(field) {  

      var someVariable = document.getElementById(field+".<%= ClientID.to_s %>");
    }
Salil