Solved

combine checkbox to text

Posted on 1998-08-21
12
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

734 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