JavaScript Checkbox Validation
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- "Java Script Check Box Validation"
I have added two ways –
1. by using checkbox ID
2. by using checkbox field name.
Here is the sample code- "Java Script Check Box Validation"
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>
Implementation -
You are good Person, YES? You are good Person, YES? '
You are good Person, YES? You are good Person, YES? '
JavaScript Radio button Validation
Radio button validation- Radio button and checkbox validation both are almost similar to each other.
To validate checkbox you have to write “.checked” property. The same you can apply for checkbox. Radio button returns value ‘true’ if it’s selected, otherwise its returns ‘false’. For radio button validation you don’t need to consider “true” parameter, JavaScript understands this parameter automatically. You can easily get the value of radio button field using their name or using their id. Below is script snap and actual implementation of this script is added. Try it and refer this to customize, accordingly you/ your requirement by changing field name or id name.
Script Snap:
<script>
function ValidateRadioButton() {
var RdBtn_Object=document.getElementsByName('Loc');
var Flag='No';
for (i=0; i < RdBtn_Object.length; i++) {
if (RdBtn_Object[i].checked==true) {
alert(' Your selected value is :' +RdBtn_Object[i].value);
Flag='Yes';
}
}
if(Flag=='No')
{ alert( 'You have not selected any location.');
return false;
}
}
</script>
<input type="radio" name="Loc" value="US" > US
<input type="radio" name="Loc" value="FRANCE" > FRANCE
<input type="radio" name="Loc" value="INDIA" > INDIA
<input type="radio" name="Loc" value="UK" > UK
<input type="radio" name="Loc" value="CHINA" > CHINA
<button onclick="ValidateRadioButton()">Validate Radio Button</button>
Implementation -try it!! ,
US
FRANCE
INDIA
UK
CHINA
FRANCE
INDIA
UK
CHINA
Method 2: Validate Radio Button Using 'forms[0].field.value' method
<script>
function ValidateRadioButton() {
var Rdbtn_Object=document.forms[0].Loc; // Select field using forms[0].field method
var Flag='No';
for (i=0; i < Rdbtn_Object.length; i++) {
if (Rdbtn_Object[i].checked==true) {
alert(' Your selected value is :' +Rdbtn_Object[i].value);
Flag='Yes';
}
}
if(Flag=='No')
{ alert( 'You have not selected any location.');
return false;
}
}
</script>
<form name="form" method="post">
<input type="radio" name="Loc" value="US" > US
<input type="radio" name="Loc" value="FRANCE" > FRANCE
<input type="radio" name="Loc" value="INDIA" > INDIA
<input type="radio" name="Loc" value="UK" > UK
<input type="radio" name="Loc" value="CHINA" > CHINA
<button onclick="ValidateRadioButton()">Validate Radio Button</button>
</form>
Implementation -try it !
XPage Tutorial-Simple Export to Excel Server Side JavaScript
Open your XPage and copy this code on 'afterRenderResponse' XPage
event. To
run this code , call this XPage , to find actual implementation of this script please click here
//////
Your code Started - Copy from here
var myDatabase:NotesDatabase=session.getDatabase(database.getServer(),"xpagecontrols.nsf");
//
Copyright xpagedomino (www.xpagedomino.com)
//
Contact admin@xpagedomino.com for any comment
//
Trusted code fully tested by 'xpagedomino.com
var myView:NotesView = myDatabase.getView("byNameProfile");
var myViewNav:NotesViewNavigator = myView.createViewNav();
var response = facesContext.getExternalContext().getResponse();
var DataWriter = facesContext.getResponseWriter();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename='exporttoexcelSSJS.xls'");
var viewEntry:NotesViewEntry = myViewNav.getFirst();
var thead:string = "";
var tr:string = "";
thead="<th>FirstName </th>"
thead=thead+"<th>
LastName </th>"
thead=thead+"<th>
DOB </th>"
thead=thead+"<th>
City </th>"
thead=thead+"<th>
Country </th>"
while (viewEntry != null) {
tr=tr+"<tr>"
tr=tr+"<td>"+viewEntry.getColumnValues()[0]+"</td>"
tr=tr+"<td>"+viewEntry.getColumnValues()[1]+"</td>"
tr=tr+"<td>"+viewEntry.getColumnValues()[2]+"</td>"
tr=tr+"<td>"+viewEntry.getColumnValues()[3]+"</td>"
tr=tr+"<td>"+viewEntry.getColumnValues()[4]+"</td>"
tr=tr+"</tr>"
viewEntry
= myViewNav.getNext(viewEntry);
}
DataWriter.write("<table
border='1'>"+thead+tr+"</table>");
DataWriter.endDocument();
//////
Your code Ends -Copy Code ends here
Read our top 7 articles-
Subscribe to:
Posts
(
Atom
)
No comments :
Post a comment