Dynamically passing a textbox to javascript to get the text value

Hi,
I need a little bit of help.
I am collecting text from an asp.net text box to process in a user control.
It works fine as long as I hard-code the ID of the text box into the Javascript function.
I need to change this process now to a non hard-coded value. The function has to dynamically accept the ID of a text box and then get the text value of the text box. Can someone help me change my Javascript? Here is the line I hard-coded in to get the reference to the text box. 

function check() {

 var UsersText = document.getElementById('');

}
0
kelasings
9/28/2007 5:22:29 AM
asp.net.client-side 24353 articles. 1 followers. Follow

2 Replies
1710 Views

Similar Articles

[PageSpeed] 32

function check(x){
var UsersText = document.getElementById(x);
alert(UsersText.value);}

Then in your code behind:

TextBox1.Attributes.Add("onchange", "check(this.id);") 


Regards Mike
[MVP - ASP/ASP.NET]
My site
0
Mikesdotnetting
9/28/2007 7:19:08 AM

Instead of passing the ID and then fetching the element in the function, you can alternatively just pass the element itself...

    function check(elem) {
        alert(elem.value);
    }

Code-behind...

    Textbox1.Attributes.Add("onchange", "check(this);")


Hope this helps!  Please mark the helpful post(s) as Answer.

 


Josh Stodola ← Come check out my blog!
0
JoshStodola
9/28/2007 3:15:38 PM
Reply:

Similar Artilces:

Getting Textbox Watermark Text in client side javascript
Can somebody tell me how I can go about grabbing the Text value of a TextBoxWatermark control from client side javascript?  I need to make a comparison/validation if a text box has been filled out (non-blank) and of course the watermark fills in the text value of the text box when grabbing the property (of the text box) per javascript? So, I need to somehow grab the text from the watermark in javascript and then compare to the text box contents to see if the text in the textbox is the water mark text or not.  Any information would be greatly appreciated.  Thanks!  Th...

Get the Dropdownlist text and value using Javascript from client side
Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)            &nb...

pass client textbox value to a server side textbox
HiDoes anyone know how in javascript to pass a client side textbox value to a server side textbox?Thanks in advance.Graham. An asp textbox is a resular textbox. so you do it the same way.document.formName.elementName.value = document.formName.elementName2.value;One thing to note is that the asp textbox is going to have a slightly different name then what you named it.EricPascarello.com | Twitter epascarello | LinkedIn...

How do i pass a dynamic value to a javascript and textbox
hello guys, I have a textbox and javascript in my .net page. that limits the amount of characters entered to 160. How do i pass a dynamic value to the  1. Javascript 2. The textbox Here is my code, both have limits of 160 characters. I tried adding a declaration of an interger and assigning a value to it on my page load and replacing the 160 with <% = limit%> where limit is the dynamic integer value, but it gives an error. Here is my code,  <asp:TextBox ID="Message" runat="server" Height="120px" Width="250px" onkeydown="...

Get textbox value in client side
My problem is that in my ascx file i have a textbox & a input buttom with a javascript function that will validate the textbox: .... <script lang="javascript"> function Test() { if (document.all.txt1.value == "") { alert(); return; } } </script> .... <asp:textbox id="txt1" runat="Server"></textbox> <input type=button id="cmd1" onclick="javascript:Test();" value="Add"> .... But the function don't work, because the textbox control isn't...

pls help: how to get client-side HTML "text field" value from a server side button
i copy some javascript from somewhere so user can choose pick up a date from a calendar and display the date onto a HTML text field. I have no knowledge in writing client side script(i.e. write code in html) can i write some code in a server-side button to get the value in the HTML text field??? i tried: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click textbox1.text = document.getElementById("htmltext").value End Sub but "document" is highlighted, and say isn't declar yet. and...

How to pass in value to javascript from database or let javascript to get value from database?
I am trying to use google map api to do some web based application.On the map, the javascript needs latitude and longitude from database to draw a marker on page load, I am wondering how can I get the data from database to do that? The map part will be like a image, won't change.Do I need Ajax?Thank you.  hanxiao:I am trying to use google map api to do some web based application.On the map, the javascript needs latitude and longitude from database to draw a marker on page load, I am wondering how can I get the data from database to do that? The map part will be like a image, won&...

Dynamically added Textbox with javascript text value
Hello, i had an aspx page which contains some dynamically added Textbox controls within a placeholder control. I want to be able to be able to set the value for the textboxes by calling some client side javascript but can't seem to work it out or find any good info. Here's what i have in my code behind page.. <-- code --> XmlNodeList columns = responseDocument.SelectNodes("//search/column"); int colCount = columns.Count; XmlElement column; TextBox txt; for (int colIdx=0; colId...

How to get TextBox text value from a javascript variable ?
How can I get text value from a javascript variable ?Example:Javascript function: var text="Hello";function GetText() { return text;} Here I need to get a text value from a javascript function.Code like this:  <asp:TextBox ID="txtMyText" runat="server" text="GetText()" />How to do it?  Try this: <form id="Form1" method="post" runat="server"> <asp:TextBox id="txtMyText" runat="server"></asp:TextBox></form <script type="text/javascript&qu...

dynamic add a few textBox by Javascript (client side)
VS.NET 2003, Framework 1.0 , ASp.net (VB) , SQL 2005 i'm having a problem is ...i 'm using js to add a few textbox dynamically when i clicked  AddNewRow()so when i wanna use (server side) VB codebehind to get the txtbox value....it look like canot get it.... bcoz the txtbox is like not defined in WEB page.    HOw ?????? helps thx Hello, I am afraid you could not access the TextBox from Server side when you create the TextBox from client side. The Server knows nothing about the TextBox Control. My suggestion is if you really want to avoid postback when you ad...

How to pass textbox object to client-side JavaScript?
First, I wonder if there is a way to pass an asp.net TextBox object to JavaScript for manipulation. If yes, how? I tried this: textbox1.Attributes.Add("onBlur", "JavaScript: return myFunction(this, '" + lblCharacterLeft.ClientID + "');"); And now when I do an alert box of "this" I got "[object]" but when I do an alert box for lblCharacterLeft I got "ctl00_cpMain_lblCharacterLeft" instead. I do not get an object. I don't know what ctl00 is but the cpMain is my ContentPlaceHolder ID called cpMain on my Master page.  Second, if the above faild or will not be possible, how do I access th...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on asp.net, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

Get values set by javascript to .net enabled textbox
I have a bit of javasript that writes a value to a text box.  The text box is read only. Textbox code:<input type="text" id="txtColor1" runat="server" readonly="readonly" size="6" /> Snippet from javascript functioncolorBox = document.getElementById('<%= txtColor1.ClientID %>');colorBox.value = colorCode;  Code behind:string color1 = txtColor1.Value Whenever I attempt to get the value out of the text box after it has been changed by the javascript, it always reverts back to the old data and not the new. Anyo...

Passing values between client and server side (Javascript to C#)
I would like to access client side values from the code behind.Say I open a window like this popWindow = window.open("data_list.aspx", "dataWindow", 'toolbar,width=150,height=100')  How can I get the window name "dataWindow" from that current window or the parent window? Any other examples accessing variables between server side (C#) and client side (JavaScript) would be greatly appreciated. Regards -WH   Page.Request.ServerVariables["SCRIPT_NAME"] will get the name of the current page.  You can also pass values in a querystring, which will make them access...

Web resources about - Dynamically passing a textbox to javascript to get the text value - asp.net.client-side

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/16/2015 6:10:54 AM