Mohd Malaka Weblog

About anything….

  • Welcome


    Welcome to my Weblog. Here I post about anything, mainly about programming. Enjoy

  • Archives

  • Flickr Photos

    Dublin





    Dublin Buildings

    In Dublin Zoo

    More Photos
  •  

    June 2008
    M T W T F S S
    « May   Jul »
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30  
  • free counters

Archive for June 17th, 2008

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

Posted by malakablog on June 17, 2008

         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”);      

                    }

                }

            }

 

 

 

 

 

 

 

Posted in Uncategorized | Tagged: , , , , | 1 Comment »