tcuos
12-10-2004, 01:31 PM
Hi,
as many before me I am very new at this. But hopefully someone out ther can help :-)
I have the following script:
<script language="javascript">
<!--
function check() {
var theform;
var list = "";
var first = true;
//browser detection
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.__aspnetForm;
}
else {
theform = document.forms["__aspnetForm"];
}
for(var i=0; i<theform.elements["box"].length; i++)
{
if(theform.elements["box"][i].checked)
{
if(first)
{
list = "?"+list+"sem"+i+"="+theform.elements["box"][i].value;
first = false;
}
else
{
list = list+"&sem"+i+"="+theform.elements["box"][i].value;
}
}
}
if(!first)
{
list = "<%=RegisterPageName()%>"+list;
}
else
{
list = "<%=CurrentPageName()%>";
}
return list;
}
// -->
</script>
This script will traverse a form containing checkboxes and get values based on the checkboxes that are checked.
The problem with this script is that when the form only has one element, which is a checkbox, it will not return the string with the value. But for 2 or more checkboxes it works OK. Why? ? ?
I can't say I fully understand the script either :-)
Appreciate any input, anyone.
Thx,
tcuos
as many before me I am very new at this. But hopefully someone out ther can help :-)
I have the following script:
<script language="javascript">
<!--
function check() {
var theform;
var list = "";
var first = true;
//browser detection
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.__aspnetForm;
}
else {
theform = document.forms["__aspnetForm"];
}
for(var i=0; i<theform.elements["box"].length; i++)
{
if(theform.elements["box"][i].checked)
{
if(first)
{
list = "?"+list+"sem"+i+"="+theform.elements["box"][i].value;
first = false;
}
else
{
list = list+"&sem"+i+"="+theform.elements["box"][i].value;
}
}
}
if(!first)
{
list = "<%=RegisterPageName()%>"+list;
}
else
{
list = "<%=CurrentPageName()%>";
}
return list;
}
// -->
</script>
This script will traverse a form containing checkboxes and get values based on the checkboxes that are checked.
The problem with this script is that when the form only has one element, which is a checkbox, it will not return the string with the value. But for 2 or more checkboxes it works OK. Why? ? ?
I can't say I fully understand the script either :-)
Appreciate any input, anyone.
Thx,
tcuos