Recent Posts

 

Javascript Field Validation

Tuesday, 19 May 2015




Check box validation, Check box returns value ‘true’ if it’s selected, otherwise its returns ‘false’. For checkbox validation you don’t need to consider true parameter, JavaScript understands this parameter automatically.
You can get the value of field or text box using their name or using their id. Below is script with pasted, you can customize accordingly you/ your requirement by changing field name or id name.

I have added two ways –
1. by using checkbox ID
2. by using checkbox field name.

Here is the sample code-

[<html>
<body>

You are good Person, YES?  <input type="checkbox" id="Chkbox">
<button onclick="checkboxValidate()">Submit</button>


You are good Person, YES?  <input type="checkbox" name='ChkboxNme' id="Chkbox">
<button onclick="checkboxValidate2()">Save</button>'

<script>
function checkboxValidate() {
    if(document.getElementById("Chkbox").checked)
    alert('Yes! you are good person!!!')
    else
    { alert('Still confused ? please select checkbox.') ; return false }
}

function checkboxValidate2() {
    if(document.getElementsByName("ChkboxNme")[0].checked)

    alert('Yes! you are good person!!!')
    else
    { alert('Still confused ? please select checkbox.') ; return false }
}

</script>

</body>
</html>]



Implementation of above code-   try yourself

Validate check box using check box id
You are good Person, YES?
Validate check box using check box name
You are good Person, YES? '








No comments:

Post a Comment

 

ALL Tutorials

xPage Tutorials

Search

Lotus Notes Security


Contact Us

Name

Email *

Message *