Problem with JS syntax

Discussion in 'Programming' started by camel021, Jul 20, 2012.

  1. #1
    Hi, I have problem with JS syntax, I have syntax as below:

    document.getElementById('<%= SearchCriteriaControls.FindControl("PoleWyboru").ClientID %>').value = getQuerystring(array);

    and it works.

    but when I want to pass in FindControl argument as controlID:

    var pole = "PoleWyboru";
    document.getElementById('<%= SearchCriteriaControls.FindControl("'+ pole +'").ClientID %>').value = getQuerystring(array);

    I've got object null reference. Why I can't pass argument to findControl method in JS ?

    I have loop like this:

    for (var i = 0; i < array.length; ++i) {
    var pole = "PoleWyboru";
    document.getElementById('<%= SearchCriteriaControls.FindControl("'+ pole +'").ClientID %>').value = getQuerystring(array);
    }

    thanx for any help !
     
    camel021, Jul 20, 2012 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    I guess its a mistake with the following line :

    
    document.getElementById('<%= SearchCriteriaControls.FindControl("'+ pole +'").ClientID %>').value = getQuerystring(array[i]);
    
    Code (markup):
    Try changing ur code to this :

    
    var pole = "PoleWyboru";
    var clientId = <%= SearchCriteriaControls.FindControl(pole).ClientID %>
    document.getElementById(clientId).value = getQuerystring(array[i]);
    
    Code (markup):
     
    Unni krishnan, Jul 22, 2012 IP