Solved

combine checkbox to text

Posted on 1998-08-21
12
199 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now