Click to See Complete Forum and Search --> : forms and checkboxes


jumpyg
09-11-2003, 12:33 PM
Hi,

I'm trying to create a search interface that will allow a user to search multiple web sites. You can click a series of checkboxes to search one, two, three, or more sites at the same time. The back end is already taken care of.

I have a hidden <input> tag that passes the domains to be searched to another program. The value attribute on the <input> tag needs to change depending on what checkbox is checked.

Example:
<input type"checkbox" name="domains" value="foo.com">
<input type"checkbox" name="domains" value="bar.com">
Checking these two checkboxes will add their values to the following hidden input tag:

<input type="hidden" name="domain_list" value="foo.com;bar.com">

Any idea how to do this? Thanks a lot!

Fang
09-11-2003, 01:35 PM
<script type="text/javascript">
<!--
function SearchSites(f) {
for(var i=0; i<f.length; i++) {
if(f.elements[i].name=="domains" && f.elements[i].checked==true) {
f.domain_list.value+=f.elements[i].value+";";
}
}
}
//-->
</script>

</head>
<body>
<form action="#" onsubmit="SearchSites(this); return false;">
bar.com<input type="checkbox" name="domains" value="bar.com"><br />
foo.com<input type="checkbox" name="domains" value="foo.com"><br />
def.com<input type="checkbox" name="domains" value="def.com"><br />
<input type="text" name="domain_list" value=""><br />
<button type="submit">submit</button>
</form>
</body>

jumpyg
09-15-2003, 07:47 AM
Fang,

Thanks for the help, but can I do the same thing, but place the domain_list in a hidden tag instead of a text box? Example:
<input type="hidden" name="domain_list" value="">

I need the domain list to go in the value attribute.

Thanks,

JG

Fang
09-15-2003, 11:14 AM
Yes, I only left it as type="text" so yuo could see the result.
I forgot to mention that ;)