0

I have a function where I pass ID parameters as objects into a javascript function but the browser does not pick it up.

<div id="searchByUser">
    <input type="text" runat="server" id="txtSearchByEmail"  onclick="ButtonEnabled('butSearchByEmail', 'txtSearchByEmail')" onkeyup="ButtonEnabled('butSearchByEmail', 'txtSearchByEmail')" />
   <input type="button" runat="server" id="butSearchByEmail" onserverclick="butSearch_Click" value="Search User" disabled/>
</div>

if however I do this instead ButtonEnabled('MainContent_butSearchByEmail', 'MainContent_txtSearchByEmail') it works fine.

I got this information from the browser(Google Chrome)

Is there a way of doing this without 'hard coding' it like this?

this is the javascript function

function ButtonEnabled(objButton, objText) {
    var t = document.getElementById(objText);
    var b = document.getElementById(objButton);
    if (t.value.length > 1) {
        b.disabled = false;
    }
    else {
        b.disabled = true;
    }    
}
6
  • it would be helpful to see the code of your ButtonEnabled function Commented Jun 13, 2013 at 12:17
  • hmmm, normaly it should work like you expected. Are you using frames or something else? Is the id of your element not txtSearchByEmail in your html sourcecode? Commented Jun 13, 2013 at 12:22
  • I might me wrong but if you try by passing "document.getElementById(objButton)" instead of b in you condition it should work better Commented Jun 13, 2013 at 12:24
  • please ensure that there is only one element with that id in your code Commented Jun 13, 2013 at 12:28
  • @VBB that will not make any difference. Commented Jun 13, 2013 at 12:29

1 Answer 1

1

Looking at your code, you're using asp.net. You have to use ClientID

<div id="searchByUser">
    <input type="text" runat="server" id="txtSearchByEmail"  onclick="ButtonEnabled('<%= butSearchByEmail.ClientID %>', '<%= txtSearchByEmail.ClientID %>')" onkeyup="ButtonEnabled('<%= butSearchByEmail.ClientID %>', '<%= txtSearchByEmail.ClientID %>')" />
   <input type="button" runat="server" id="butSearchByEmail" onserverclick="butSearch_Click" value="Search User" disabled/>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.