Solved

combine checkbox to text

Posted on 1998-08-21
12
213 Views
Last Modified: 2013-12-25
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
Comment
Question by:milen
  • 7
  • 4
12 Comments
 

Author Comment

by:milen
ID: 1828247
Edited text of question
0
 

Author Comment

by:milen
ID: 1828248
Edited text of question
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1828249
Do you have access to CGI or ASP?  If so, you can parse the Query String and get the values...

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:milen
ID: 1828250
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
 
LVL 2

Expert Comment

by:bernfarr
ID: 1828251
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
 

Author Comment

by:milen
ID: 1828252
NO. It doesn't works!!!
0
 
LVL 2

Expert Comment

by:bernfarr
ID: 1828253
Can you give a pointer to your web page, or the source code?
0
 

Author Comment

by:milen
ID: 1828254
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
 

Author Comment

by:milen
ID: 1828255
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
 
LVL 2

Accepted Solution

by:
bernfarr earned 100 total points
ID: 1828256
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
 

Author Comment

by:milen
ID: 1828257
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
 
LVL 2

Expert Comment

by:bernfarr
ID: 1828258
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: 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question