zachvaldez
asked on
Click a textbox and navigate to a page
What is the javascript code or other approaches if server side code won't do
to navigate to a page when a textbox is clicked since Textbox does not have a click event?
to navigate to a page when a textbox is clicked since Textbox does not have a click event?
add this in the head section of the page :
where TextBox1 is the ID of your textbox
http://beyondrelational.com/modules/2/blogs/61/posts/11206/all-about-client-id-mode-in-aspnet-4.aspx
<script type="text/javascript">
window.onload = function() {
document.getElementById("<%= TextBox1.ClientID %>").onclick = function() {
location.href = "http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27868878.html";
}
}
</script>
where TextBox1 is the ID of your textbox
http://beyondrelational.com/modules/2/blogs/61/posts/11206/all-about-client-id-mode-in-aspnet-4.aspx
ASKER
there is a syntax error looking for a missing ";" somewhere..
not in my code... generally not in javascript
ASKER
ok I found the error and it worked .However, If I set the textbox to readonly, this thing would would not work.
I don't want the ability to edit the textbox but can only be clicked and navigate to the url.
Is it possible to set textbox not editable with keyup event?
I don't want the ability to edit the textbox but can only be clicked and navigate to the url.
Is it possible to set textbox not editable with keyup event?
>If I set the textbox to readonly, this thing would would not work.
That's wrong until you're using .net to do that....
use readonly="readonly"
That's wrong until you're using .net to do that....
use readonly="readonly"
<asp:TextBox id="TextBox1" runat="Server" ></asp:TextBox>
<script type="text/javascript">
window.onload = function() {
document.getElementById("<%= TextBox1.ClientID %>").setAttribute("readonly", "readonly");
document.getElementById("<%= TextBox1.ClientID %>").onclick = function() {
location.href = "http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27868878.html";
}
}
</script>
ASKER
Is it possible to add another textbox "textbox2" for instance and navigate it to a diff. url?
I tried to do that but did not work.
Should I repeat the window.onload for it to work?
I tried to do that but did not work.
Should I repeat the window.onload for it to work?
>Is it possible to add another textbox "textbox2" for instance and navigate it to a diff. url?
yes
>I tried to do that but did not work.
so post a link to you page or you code...
yes
>I tried to do that but did not work.
so post a link to you page or you code...
ASKER
well I just add the code..
window.onload = function() {
document.getElementById("< %= TextBox1.ClientID %>").setAttribute("readonl y", "readonly");
document.getElementById("< %= TextBox1.ClientID %>").onclick = function() {
location.href = "https://www.experts-exchange.com/questions/27868878/Click-a-textbox-and-navigate-to-a-page.html";
document.getElementById("< %= TextBox2.ClientID %>").onclick = function() {
location.href = "school.aspx";
}
}
window.onload = function() {
document.getElementById("<
document.getElementById("<
location.href = "https://www.experts-exchange.com/questions/27868878/Click-a-textbox-and-navigate-to-a-page.html";
document.getElementById("<
location.href = "school.aspx";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I forgot to mention I also have a query string added at the end of
location.href = "school.aspx?hid=xxxxx"; for example
How will I add the querystring value?
location.href = "school.aspx?hid=xxxxx"; for example
How will I add the querystring value?
create a new question...
why would you want to navigate on textbox click? It is not something that is used generally.
I am not much aware of .NET textboxes but in html text boxes click event is there.
Look at following link
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox_events.aspx
Hope this will help you.
Thank you
Amar Bardoliwala