Text Changed and javascript confirm box
-
I have a textbox which is created dynamically in page_load. TextBox tb = new TextBox(); tb.id = "ID1"; tb.text = GetfromDB(); tb.TextChanged +=new EventHandler(tb_TextChanged); Now i want to add a javascript confirmbox as tb.Attributes.Add("onchange","javascript:return confirm('Data has Changed. Click OK To Continue');"); If the user clicks ok then continue to tb_TextChanged function and if user clicks cancel i want to restore the previous value of textbox. How can i write the javascript function? Thanks
-
I have a textbox which is created dynamically in page_load. TextBox tb = new TextBox(); tb.id = "ID1"; tb.text = GetfromDB(); tb.TextChanged +=new EventHandler(tb_TextChanged); Now i want to add a javascript confirmbox as tb.Attributes.Add("onchange","javascript:return confirm('Data has Changed. Click OK To Continue');"); If the user clicks ok then continue to tb_TextChanged function and if user clicks cancel i want to restore the previous value of textbox. How can i write the javascript function? Thanks
Basically when a postback occurs, everything in the page gets recreated again. If it is not posted back you need to somewhere hold the initial values and show to the items. You can make a global object say
var myarray = {};
myarray["textbox1"] = document.getElementById("textbox1").value;
..
..
..When you restore, set the value from myarray to actual controls.
document.getElementById("textbox1").value = myarray.textbox1;
...
...
...what is the problem with that. If the page is not posted back you can do this easily. :thumbsup:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Basically when a postback occurs, everything in the page gets recreated again. If it is not posted back you need to somewhere hold the initial values and show to the items. You can make a global object say
var myarray = {};
myarray["textbox1"] = document.getElementById("textbox1").value;
..
..
..When you restore, set the value from myarray to actual controls.
document.getElementById("textbox1").value = myarray.textbox1;
...
...
...what is the problem with that. If the page is not posted back you can do this easily. :thumbsup:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>I do not want to store values without any event. I have many textboxes and i want to store the inital value only based on some event. Is there some event like onfocus or onkeydown for the textbox where i can store only for the textbox which is supposed to be changed. Thanks
-
I do not want to store values without any event. I have many textboxes and i want to store the inital value only based on some event. Is there some event like onfocus or onkeydown for the textbox where i can store only for the textbox which is supposed to be changed. Thanks
of course there is. You might use
onfocus = "javascript:myarray[this.id]=this.value"
to initializemyarray
with initial value if you want. No big deal, do it whatever you feel like. :rose:Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>