javascript interview questions

How to get value from a textbox?

alert(document.getElementById('txtbox1').value);

How to get value from dropdown (select) control?

alert(document.getElementById('dropdown1').value);

How to get value from RadioButtonList control?

Here id is the name property of the RadioButtonList
function GetRadioButtonValue(id)

        {

            var radio = document.getElementsByName(id);

            for (var ii = 0; ii < radio.length; ii++)

            {

                if (radio[ii].checked)

                    alert(radio[ii].value);

            }

        }

How to get CheckBox status whether it is checked or not?

alert(document.getElementById('checkbox1').checked);
if it will be checked you will get true else false.

How to toggle display an HTML element?



function ToggleFollowingText(id)
{
document.getElementById(id).style.display == '' ? document.getElementById(id).style.display = 'none' : document.getElementById(id).style.display = '';
}


In above function you need to pass id of the html element as the parameter.
If the control is already displaying then it will hide otherwise it will be shown.
Name the DataTypes of JavaScript?


1)Integer
2)String
3)Boolean
4)Null

No comments:

Post a Comment