how to change a button's text in javascript

I have a button called btnFailureReport. Once a javascript function was called, I want the text of the btnFailureReport can be changed. Please see the code below.

The problem is the "text" of the btnFailureReport was changed only for look. If I want to save the text to the database, I found the text is still the old text. So I put the two alert box (commented out) in the function to test. The result for the first one (ctrl.value) is the "hello" which is right. But the result for the second one (ctrl.text) is "undefined", which means the "text" was not changed.

Does  anybody knows how to fix this problem?

My javascript function is like this:

function GetFileName()
    var ctrl =document.getElementById("ctl00_ContentPlaceHolder1_tcRMACAR_TabPanelCAR_tabPanelInsideCar_tpContainment_btnFailureReport");
    //ctrl.value =document.getElementById("ctl00_ContentPlaceHolder1_tcRMACAR_TabPanelCAR_tabPanelInsideCar_tpContainment_FileUpload1").value;
    ctrl.value = "hello";
    ctrl.text = ctrl.value;      
9/4/2008 4:50:49 PM 93655 articles. 5 followers. Follow

10 Replies

Similar Articles

[PageSpeed] 12

I tried to put this code inside the GetFileName() function:

<%SetData("Hello"); }%>;

and add a function in C# code:

    public void SetData(string txt)
        btnFailureReport.Text = txt;
        lbFailure.Visible = true;
        lbFailure.Text = "txt: " + btnFailureReport.Text;

It does not run until I click on the button. Also, after I click on the button, lbFailure shows the right content.

So strange.

9/4/2008 7:03:39 PM
Javscript runs only on the client side. To save the data to a database or whatever, you need a postback which does this on the server side. The setData is server side code, but you still need a postback.
9/4/2008 7:22:08 PM

 Hi Friend,

 As far as I know,  In Javascript, document.getElementById("btnFailure").value returns the text which is displayed on the Button.

 So If u want to change the text of the button in javascript upon clicking of the button, Just use document.getElementById("btnFailure").value to set the text u want to display and using __EVENTTARGET and __EVENTARGUMENT, change the text of button while saving into DB



9/4/2008 7:37:45 PM

Not sure how to do that: using __EVENTTARGET and __EVENTARGUMENT, change the text of button while saving into DB

9/4/2008 7:52:33 PM
9/5/2008 5:14:09 AM
C# Request["__EVENTTARGET "] to get button name, Request["__EVENTARGUMENT"] get value in code behind.
Don't forget to click "Mark as Answer" on the post(s) that helped you.
9/5/2008 5:37:47 AM

Thank you!  I'm not sure what do you mean by using Request.Form["__EVENTTARGET "] to get button name.

I know the button ID. it's btnFailureReport.  

9/5/2008 2:35:58 PM

After the text on the button was changed by the javascript function, I viewed the source. And found on the source view, the value of the button is same as before, it did not change! How's that?Crying

9/5/2008 3:05:53 PM

If you want to save the text changes to the database, you could use ajax, it will get the new value you changed.

This video will show you how to use ajax  


Don't forget to click "Mark as Answer" on the post(s) that helped you.
9/5/2008 4:22:33 PM

I figured it out. Use a hiddenbutton to record the value. Then get the value from the hiddenbutton after post back. Hiddenbutton is the key.

9/15/2008 2:52:56 PM

Similar Artilces:

How to change txt2.text when the txt1's.text changes using JavaScript?
Hello! I want some JavaScript (or any other client-side) solution for my problem thatdescribed here: In a few words, my problem is that i don't know the way to change the txt2.text valuewhen the txt1.text value changes... Please read the first...I want only JavaScript solution... Thank you very much! Like this? <input type="text" id="TextBox1" name="TextBox1" onchange="textBox1OnChange(this);" runat="server" /><input type...

Can I change a treeview's text size depending on what my browser's text size is set to?
I'm using a treeview on a .net 2.0 page and all is working fine with it in Internet Explorer.  However if I go to View -->  Text Size --> Largest on my browser's menu, all the text on my page appears huge apart from the text in the treeview which remains the same size as it always was.  Is there a way to fix this so that this text will also increase in size? Many Thanks. Make sure the font size is not set in the control.  And use css to help moderate your pages look and feel. HTH,Joe JohnstonIf a picture is worth a 1000 words, a sample application ...

superreview requested: [Bug 224546] Change Win 'Regional Settings' -> lose button functions & text : [Attachment 136434] update with smontagu's concerns addressed
Jungshik Shin <> has asked Christopher Blizzard <> for superreview: Bug 224546: Change Win 'Regional Settings' -> lose button functions & text Attachment 136434: update with smontagu's concerns addressed ------- Additional Comments from Jungshik Shin <> asking for r/sr. perhaps not this weekend although i'd not complain if you could review this weekend :-) ...

superreview granted: [Bug 224546] Change Win 'Regional Settings' -> lose button functions & text : [Attachment 136434] update with smontagu's concerns addressed
David Baron <> has granted Jungshik Shin <>'s request for superreview: Bug 224546: Change Win 'Regional Settings' -> lose button functions & text Attachment 136434: update with smontagu's concerns addressed ------- Additional Comments from David Baron <> >Index: intl/locale/src/windows/nsIWin32LocaleImpl.cpp > struct iso_pair > { > char* iso_code; How ab...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

using javascript to change .net web form properties
Hello everyone, I'm fairly new to ASP.NET and I'm trying to find the best solution to this problem I'm having.  I believe ultimately what I need to be able to do is change the ImageUrl value via javascript of an ImageButton.  A small example of what I'm working on can be found here in a javascript form: is a simple data input method for a survey. There are three distinct columns, when you select a number within a column it will change the .gif image to show it's selected and then populate the textbox with that value.  I...

How to change the text of UsersControl's Button which in a webpart?
Hi all! I have a problem and i can't find the discussion. So I have a user control, like this:  1 using System; 2 using System.Collections; 3 using System.Configuration; 4 using System.Data; 5 using System.Linq; 6 using System.Web; 7 using System.Web.Security; 8 using System.Web.UI; 9 using System.Web.UI.HtmlControls; 10 using System.Web.UI.WebControls; 11 using System.Web.UI.WebControls.WebParts; 12 using System.Xml.Linq; 13 14 public partial class HirekUC : System.Web.UI.UserControl 15 { 16 public string ButtonText; ...

How to change fieUpload control's button text?
Hi, Is it possible to change the button's text in fileUpload control in 2.0? Thanks I never believe in systems. Instead, people. Normally there is no method availale for renaming the control button's text.. when you say file upload do you mean <input type="text">?  If so, this cannot be changed through it attributes.  However, there is a pretty clever hack to change the look and feel of it with css  Community Coder I have an article which explains how to upload like GMail. http:/...

How to change the 'edit' button to 'Update'+'Cancel' button in Gridview
Hi all, I'm using a commandField 'edit' button in a Gridview which I hope to be changed to a 'update' and a 'cancel' button when the 'edit' button is pushed. My codes are as follow.  My problem is that I don't know what codes should be added to make the change I mentioned to happen. THanks a lot for your assistance. TOny<%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><%@ Import Namespace="syste...

Changing a Radio Button's Label in Javascript? Is this possible?
Is it possible to change the "label for" an input radio button within javascript? I tried setting the ID of the Label but get "the name does not exist in the current context" error. document.getElementById('<%=lblPopTest.ClientID %>').innerText = q;.....<input id="RadioSaveProm" name="Radio" runat="server" type="radio" />   <label for="RadioSaveProm" id="lblPopTest">load this from javascript?</label><br />  <html xmlns="

Can you change a linkbutton's text using client side javascript?
I have a linkbutton which opens a new window. When the user closes the new window, I want to change the text of the original linkbutton. The issue isn't the popup window since know how to use window.opener. The problem is that I don't know how to use javascript to change the inner text of the linkbutton which I know is rendered as anchor tags. Any suggestions? Hi, on the Page where the LinkButton is, you can output the client-side ID of the LinkButton with it's ClientID property assuming you have <asp:LinkButton ID="LinkButton1" runat="server" Text="Hello" />So you could ou...

User's Name Changed
We are using Groupwise 5.5 I have a user that recently married. I have created a Groupwise alias for the new name, but how do I go about changing the Groupwise Object/User ID and NDS account ID and keep their email account intact? Thanks, J.Jensen Jeff, you can simply rename the Groupwise account. No mail loss. Uwe -- Novell Support Connection Volunteer SysOp Please don't send me support related e-mail unless I ask you to do so. ...

Does anyonw know how to fire a JAVAscript function when the TextBox's Text have been changed.
Does anyonw know how to fire a JAVAscript function when the TextBox's Text have been changed. Hello there,Hope this could be helpful  TexBoxID.Attributes.Add("fun1", "return JavaScriptFunctionName(event)"); fun1 is the name of event which is fired when text of text box is changed i.e. textchanged event. Thank you,   Thanks,Mark as Answer if it helps u....Devaang Hi,Try this<script language='javascript' type='text/javascript' > function txtChange(para){    alert(para.value) } <...

Problem in web service's web method's parameters.
Hello All,I am tring to consume a Java web service in ASP.NET(c#) application.In the web service, the web method 'checklogin' accepts 2 string parameters only, with return type a boolean variable. But, when I use that method in my ASP.NET application it shows me 4 parameters in the definition namely 2 string parameters(which should be there) and extra 2  boolean type OUT parameters. Out of these 2 extra OUT parameters, in the 1st parameter I get the return variable of the web method which I called/used and in the 2nd parameter, its showing nothing (means its showing default...

Web resources about - how to change a button's text in javascript -

Resources last updated: 11/22/2015 9:08:51 AM