Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am facing one issue. I am setting value to the textbox on onclick event through javascript but it is not showing that value in the textbox. When i inspect that element using web developr then i can see this value there. Actually this is a user control and it has several controls such as radio buttons and textbox. on selecting the radio button this textbox should populate. This issue exist only on windows safari.

I have provided my code below.
// JavaScript
function ChangeTextBox(textbox)
    {
        var prefix = textbox.id.substring(0,textbox.id.lastIndexOf("_") + 1);
        var ProductList = document.getElementById(prefix +  'HiddenProduct').value.split(";;");
        var selected;
        //MBT Phase2-Release1-LUW1
        //Begin:Kunal April-2014
        //Product selection is not working for Non-IE Browser
        if (navigator.appVersion.indexOf("MSIE") != -1) 
        {
            for(var i = 0; i < document.getElementById(prefix + 'rbgProduct').childNodes[0].childNodes.length; i++)
            {
                if(document.getElementById(prefix + 'rbgProduct_' + i).checked == true)
                {
                    textbox.value = ProductList[i];
                    selected = i;
                }
            }
        }
        else
        {
       
         for(var i = 0; i < ProductList.length-1; i++)
            {
                if(document.getElementById(prefix + 'rbgProduct_' + i).checked == true)
                {
                    $(textbox)[0].textContent = ProductList[i];
                    $(textbox)[0].innerText = ProductList[i];
                    $(textbox)[0].value = ProductList[i];
                    selected = i;
                }
            }

        }

C#
// Server Side
public override void RenderControl(HtmlTextWriter writer)
        {
            rbgProduct.Attributes.Add("onclick", "ChangeTextBox(" + txtProductDescription.ClientID + ")");
            
            txtProductDescription.Attributes.Add("readonly", "readonly");
            base.RenderControl(writer);
        }
Posted
Updated 19-Nov-14 3:41am
v5
Comments
Prasad Khandekar 19-Nov-14 9:44am    
Hello Umesh,

From your code it looks like that the client side on click handler (ChangeTextBox) is not getting reference to actual text box. Try using document.getElementById to retrieve the actual textbox reference.

Regards,
Umesh Tayade 19-Nov-14 9:52am    
Hi Prasad,

Thanks for your reply.
If it is not getting the actual reference of textbox then that value wont be set at all. But when i check this control using web developer then i can see that value. Only thing is that it not displayed in the textbox.

Thanks
ZurdoDev 19-Nov-14 11:12am    
1. Please reply to comments so that the user is notified instead of adding a new comment to your own question.
2. Why not do $(textbox)[0].val(""); to set the textbox?
GregWyatt 19-Nov-14 11:14am    
I'm not sure this is the solution since you say it is being set and you can see it, but the Jquery call you are using is incorrect. It should be $(textbox)[0].val(ProductList[i]); Here is a link to the page explaining this http://api.jquery.com/val/ val() is specifically used for input, select, and textareas. Hope this helps.
Umesh Tayade 20-Nov-14 5:26am    
Hi Greg, Ryan,
I have tried that as well but it wont works. I have tried different approaches to resolve it some of them are given below but none of them work. It works for all the browsers except safari. One thing i would like to mention is that when i switch the tab and again come back to same tab then it shows the value in the textbox. This means value is there but textbox needs to be refreshed.
1] $(textbox.id).val(ProductList[i]);
2] $(textbox.id).attr("value",ProductList[i]);
3] $(textbox)[0].textContent = ProductList[i];
4] $(textbox)[0].innerText = ProductList[i];
5] $(textbox)[0].value = ProductList[i];
6] textbox.value = ProductList[i];
7] document.getElementbyId(textbox.id).value = ProductList[i];


Thanks
Umesh Tayade

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900