Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedding javascript

Status
Not open for further replies.

TPetersonFlorida

Programmer
Aug 8, 2003
76
US
I need help embedding javascript into my aspx page. i have two text boxes and when i am typing in textbox1 on the OnKeyDown event captures what is in it and sets textbox2 to that value, all client side. How in the heck do i do this??? I have been reading and reading and can not find anything that can help me.

thanks in advance!!!!
 
I have no code right now because I dont know how to embed the javascript code into an aspx page that is using code behind forms. i know how to do it in classic asp but its totally different in asp.net.
 
Im new to asp.net too, but I have written all my client side code in the html view of the aspx page and got away with it. The code behind is mainly for server side code.
 
You can attach events to server controls like so:

txtMyTextBox.Attributes.Add("onclick","YourJSFunctionHere()");

You can use this to add any number of attributes to any server control of any type. A very useful method, indeed.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
there are a couple of ways.

[tt]Page.RegisterStartUpScript()[/tt] will embed JS on the form and execute it on the load event.

[tt]Page.RegisterClientScriptBlock()[/tt] will embed JS on the form, but you need to call the function for it to execute.

You can add attributes to controls to add the javascript funtions. Example [tt]MyTextBox.Addtributes.Add("onblur","MyJavascriptFunction();")[/tt]

You can also link javascript files in the header
[tt]<script src=[relative path of file] language="javascript" id="JS"></script>[/tt]

try this on your form
Code:
TextBox1.Attributes.Add("onKeyDown", "document.getElementByID('" & TextBox2.ClientID & "').Value = document.getElementByID('" & TextBox1.ClientID & "').Value;" )

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top