Javascript form validation

From Code Trash
Jump to: navigation, search

Radio Button

Set Radio

function setRadio(nami,idx)
{
	var al = document.getElementsByName(nami)
	for(var i=0;i<al.length;i++)
		if(al[i].value==idx)
			al[i].checked = true
}

UnSet Radio

function unSetRadio(nami)
{
	var al = document.getElementsByName(nami)
	for(var i=0;i<al.length;i++)
			al[i].checked = false
}

Get Radio

function getRadio(nami)
{
	var al = document.getElementsByName(nami)
	for(var i=0;i<al.length;i++)
			if(al[i].checked)return al[i].value
	return false;
}

Common Is Selected

Check whether any of an item in a list, radio, check is selected.
This is common for most input controls

function isSelected(ref)
{
	var ch = document.getElementsByName(ref)	
	for(var i=0;i<ch.length;i++)
		if(ch[i].checked)return true;
	return false;		
}

Checkbox validation using jquery


if($('#terms').is(':checked') == false)