• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

combine checkbox to text

I'm working with Selena Sol Database. I want visitors to check the needs (diferent group of checkbox) and send a keyword (which combines all of the checkbox selections into a value separated with SPACES) to submit to database search.
Room needs:
<input type="checkbox" name="keywords" value="TV">TV<br>
<input type="checkbox" name="keywords" value="phone">Phone<br>
<input type="checkbox" name="keywords" value="Security">Security

Sports needs:
<input type="checkbox" name="keywords" value="tennis">tennis<br>
<input type="checkbox" name="keywords" value="soccer">soccer<br>
<input type="checkbox" name="keywords" value="golf">golf

The 'keywords' value to submit database to compare must be something like:
keywords=TV phone tennis golf
(separated with SPACES)
0
milen
Asked:
milen
  • 7
  • 4
1 Solution
 
milenAuthor Commented:
Edited text of question
0
 
milenAuthor Commented:
Edited text of question
0
 
MasseyMCommented:
Do you have access to CGI or ASP?  If so, you can parse the Query String and get the values...

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
milenAuthor Commented:
I work with Selena Sol Database which is a CGI script, of course. My problem is that when I post the 'keywords' there aren't SPACES between the words selected.
0
 
bernfarrCommented:
Have you tried embedding a space in the value clauses. Like:
<input type="checkbox" name="keywords" value="TV ">TV<br>
<input type="checkbox" name="keywords" value="phone ">Phone<br>
<input type="checkbox" name="keywords" value="Security ">Security

0
 
milenAuthor Commented:
NO. It doesn't works!!!
0
 
bernfarrCommented:
Can you give a pointer to your web page, or the source code?
0
 
milenAuthor Commented:
I tested logical of the search submitting something like:
<INPUT TYPE = "text" NAME = "keywords" SIZE = "50" MAXSIZE = "60">
Typing by hand:
TV phone tennis golf
and it works fine.

When all checkbox's join in a single text, the words are not separated by spaces. It seems like spaces printing the variable on screen but they aren't spaces...
0
 
milenAuthor Commented:
The URL is:
http://www.bariloche.org/cgi-local/db-mang.cgi?setup_file=hospedaj.setup

You must go to 'VER ITEMS'

I put a test field (from the top, the second) if you try with:
bar restaurant
the search retries 4 of the 5
if you select 'bar' 'restaurant' from the checkbox (with the test box clean), the 'keywords' field appears to be fill with 'bar restaurant' but it doesn't works.
0
 
bernfarrCommented:
If you add a little JavaScript to your form, you can combine the checkbox values and pass them into your CGI routine.

Try something like:

<FORM METHOD = "post" ACTION = "http://bariloche.org/cgi-local/db-mang.cgi" onSubmit="return CombineCheck(this)">

.....
<SCRIPT LANGUAGE="JavaScript">
function CombineCheck(form)
{
      var keywordsVal = '';

      if ( form.elements['keywords1'].checked )
      {
            keywordsVal = keywordsVal + form.elements['keywords1'].value;
      }

      if ( form.elements['keywords2'].checked )
      {
            keywordsVal = keywordsVal + form.elements['keywords2'].value;
      }

      if ( form.elements['keywords3'].checked )
      {
            keywordsVal = keywordsVal + form.elements['keywords3'].value;
      }
      
      form.elements['keywords'].value = keywordsVal;
      return true;
}
</SCRIPT>
....
<input type="hidden" name="keywords" value="">
<input type="checkbox" name="keywords1" value="TV ">TV<br>
<input type="checkbox" name="keywords2" value="phone ">Phone<br>
<input type="checkbox" name="keywords3" value="Security ">Security
....

This is using the JavaScript to combine the values in the keywords and update the value in the hidden variable keyword. The CGI will process the combined set of values in keyword.

Hopefully this is enough to get you started. I believe the JavaScript should work on most browsers, it's fairly generic.
0
 
milenAuthor Commented:
Form you see is generated from CGI script. I tried to embed your javascript rutine, and adapted my var names, but there is an error:
Internet Explorer 4 Error!
Line 19
Character 3
'elements.insgastr1.checked' is not an object
Code 0

You can see the problem on line.
Do you have more ideas?
0
 
bernfarrCommented:
Sorry I wrote the code kind of quickly. Each element on the form has a name, so within the function I gave you an element is:
  form.insgastr1

It's possible that form may become a reserved word in future, so try the following as a possible script:

<SCRIPT LANGUAGE="JavaScript">
function CombineCheck(theForm)
      {
            var keywordsVal = '';
            
            if ( theForm.insgastr1.checked )
            {
            keywordsVal = keywordsVal + theForm.insgastr1.value;
            }
            
            if ( theForm.insgastr2.checked )
            {
            keywordsVal = keywordsVal + theForm.insgastr2.value;
            }
            
            theForm.keywords.value = keywordsVal;
            return true;
      }
</SCRIPT>

I think there are other problems, because when I submit this form to your site I get other errors.

I did confirm the code works by building a small form with it and trying it out, so the problem may be due to something in the CGI script.

I'm heading home for the weekend. I'll check in on Monday to see how things worked out.

Bernard
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now