Advertisements
RSS

Using onBlur event to save the value of HTML Control during postback

17 Jun

         So I was working on a web application that use HTML check box, the check box was losing its value during postback, to solve this I used the OnBlure Event

<input onBlur=’updateValue(this)’ id=”CHECKBOX1″ type=checkbox checked=”CHECKED”/>

 

 This is the JavaScript function UpdateValue:

function updateValue(inputField)

         {   

           

          

            if (typeof inputField == “string”)

            {       

                inputField = document.getElementById(inputField);   

            }   

            if (inputField.type == “select-one”)

            {

                    for (var i=0; i<inputField.options.length; i++)

                    {

                        if (i == inputField.selectedIndex)

                        {

                                inputField.options[inputField.selectedIndex].setAttribute(“selected”,“selected”);

                        }       

                    }   

            } else if (inputField.type == “text”) {       

                inputField.setAttribute(“value”,inputField.value);

            } else if (inputField.type == “textarea”) {

                inputField.setAttribute(“value”,inputField.value);

            } else if ((inputField.type == “checkbox”) || (inputField.type == “radio”))

                {       

                    if (inputField.checked)

                    {

                        inputField.setAttribute(“checked”,“checked”);

                    }

                    else

                    {

                        inputField.removeAttribute(“checked”);      

                    }

                }

            }

 

 

 

 

 

 

 

Advertisements
 
1 Comment

Posted by on June 17, 2008 in General, Photography

 

Tags: , , , ,

One response to “Using onBlur event to save the value of HTML Control during postback

  1. Hanna

    October 29, 2008 at 11:35 am

    Hi,
    great job . its really help keep it up and post more like this

    IT interview FAQs

    Regards
    Hanna

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: