Problem with Unchecked Raido Buttons in Perl Script

They have: 40 posts

Joined: Oct 2001

Hi,

I have a perl script, which takes form values and stores them in a flatfile database. Everything works fine, except...

It has some radio buttons, neither of which (yes or no) I want to be selected. But if a user fails to select either yes or no, then the script fails to send any value to the db. This makes sense, as there is no value to send. I thought I had got around this by including a hidden input with the same name as the radio button, and a generic value (ie. "-" without the quotes), which was checked. So if the user fails to select yes or no, then this value is sent, and this solves the problem.

However, if the user does select yes or no, the hidden button remains checked. This means I now have an extra field created, which I don't want. Obviously, it throws the whole database out as well.

Can anyone explain why the hidden button remains checked, and how I can get around this, while still having the yes and no buttons unchecked? Below is an example of what I mean. Thanks.

Yes
No

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

You could just make that hidden field a radio button.

The other thing I'd suggest is hacking the perl script to put "N/A" if $var==NULL

They have: 40 posts

Joined: Oct 2001

Mark,

I would like to make it a radio button, but keep it hidden. Is this possible? The reason I made it hidden is because I only want "yes" and "no" to appear.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

You could make No selected by default. Or did you also want to allow null values?

They have: 40 posts

Joined: Oct 2001

Yes. I had previously had No selected by default. But the person I'm doing it for wanted neither selected, so she could be sure that when a "yes" or a "no" came through, the user had actually selected it. I'm now trying to do it without the hidden field, so that if nothing is selected by the user, the script inserts "NS" for that value. So far much hair being torn out...

They have: 40 posts

Joined: Oct 2001

Actually, Mark,

The whole problem arose because checkboxes didn't work. I had checkboxes all over the place, but only the ones which were selected by the user were passed into the flatfile db. This meant that if there were 20 fields total, and 5 were checkboxes, and the user only selected 2 checkboxes, then 3 wouldn't show up, so the db ended up with only 17 fields, when it should have had 20. And then when I use that db to print to the screen the different lines in the db, if there are 3 lines, each with different numbers of fields, it skews the printout.

If you can explain to me how to make the value "-" appear in the db, if that checkbox isn't selected, that would solve most of my problems.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

How do you want to solve this problem?
1) hacking the perl script
2) finding a client side solution (DHTML, or other form tricks)

They have: 40 posts

Joined: Oct 2001

Well. I'm quite happy to hack the perl script if there's a way to do it so that EVERY checkbox shows up in the database, even if the user only checks 2 out of 5. If this is possible, I'd love to hack the script.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Is there any copyright on the script?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Conditional -- if it's allowable to edit the script, what you want to do is test the response, and say if there is no response (null), then return the value no.

Little conditional statements are quite easily added to existing scripts if you are allowed to edit the script.

Smiling Suzanne

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.