Avance Zone

select checkbox page load

javascript_onload_checkbox :

This javascript selects the checkbox using the indexof in pageload event

<html>
<head>
<script type="text/javascript">
var arr1 = "acd";
var arrval = "";
function load()
{
window.status="Page is loaded  here";
if ((searcharray=arr1.indexOf("a"))!=-1)
{
arrval="its A";
callalert();
document.test.checkgroup[0].checked=true;
}
if ((searcharray=arr1.indexOf("b"))!=-1)
{
arrval="its B";
callalert();
document.test.checkgroup[1].checked=true;
}
if ((searcharray=arr1.indexOf("c"))!=-1)
{
arrval="its C";
callalert();
document.test.checkgroup[2].checked=true;
}
if ((searcharray=arr1.indexOf("d"))!=-1)
{
arrval="its D";
callalert();
document.test.checkgroup[3].checked=true;
}
}
function clicked()
{
alert("Changing value manually")
}
function callalert()
{
alert (arrval);
}
document.write(’THE GIVEN VALUE OR ARRAY IS<br>);
document.write(arr1);
</script>
 
</head>
<body onload="load()">
</body>
</html>
<form name="test">
A:<input type="checkbox" name="checkgroup" onclick="clicked()"/><br />
B:<input type="checkbox" name="checkgroup" onclick="clicked()"/><br />
C:<input type="checkbox" name="checkgroup" onclick="clicked()"/><br />
D:<input type="checkbox" name="checkgroup" onclick="clicked()"/><br />
</form>
</html>

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Avance Zone