PDA

View Full Version : Submiting two inputs using one checkbox



doester
04-06-2008, 09:09 PM
I have a simple form, that has a checkbox option for db1 or db2
(both require different templates to display)

Is there a javascript way to have a db2-templete value
submited as we'll when just selecting the db2 option?

Thanks

Dr

Medyman
04-07-2008, 04:30 AM
You could just send the value through an hidden input.


<input type="hidden" name="template_value" value="template">

djr33
04-07-2008, 04:46 AM
Why don't you just react to the one value based on the receiving script?

In other words, in your PHP (or whatever) code having something like:
if ($_POST['box']==1) { $a=1; $b=2; }

doester
04-07-2008, 06:16 AM
You could just send the value through an hidden input.


<input type="hidden" name="template_value" value="template">

That won't work, I need to send a different template input value
based on which database option is checked db1 or db2 etc

If I just set a tag like this
<input type="hidden" name="mytemplate" value="template2">
and somone checks the db1 option, db1 will get that template2 as well

The default db1 already has a default templete built
nside the script itself

I know this should have been written into the database script itself
but I have to make due with what I have. and was told javascript
is the only way to do this. but its tricky

Thanks for trying

djr33
04-07-2008, 06:26 AM
As I said, do this AFTER the form is submitted. One checkbox, one value. But then two reactions.

doester
04-07-2008, 06:38 AM
As I said, do this AFTER the form is submitted. One checkbox, one value. But then two reactions.


I would ASAP, but I don't understand about what your saying
My page is html I would need some kind of javascript
to perform that. if you know where I could find that please let me know
Thanks

djr33
04-07-2008, 08:03 AM
No, you don't need Javascript. You need a serverside language, like PHP, ASP, CGI, etc.

You submit a form. Where does that go? It gets submitted to some page, which is coded to INTERPRET the data. Instead of interpreting that data as a single input, use a simple if statement to set TWO values if that one value was sent.

Now, if you don't have access to the page to which you are submitting the data, that can be more difficult and you might need to use a less reliable method like Javascript. In that case, I'd suggest a hidden input, and using Javascript to change its value when you check the box.

However, again, the best method here is interpreting it serverside. How is the data being parsed? Are you using a prebuilt script?

doester
04-07-2008, 03:55 PM
No, you don't need Javascript. You need a serverside language, like PHP, ASP, CGI, etc.

You submit a form. Where does that go? It gets submitted to some page, which is coded to INTERPRET the data. Instead of interpreting that data as a single input, use a simple if statement to set TWO values if that one value was sent.

Now, if you don't have access to the page to which you are submitting the data, that can be more difficult and you might need to use a less reliable method like Javascript. In that case, I'd suggest a hidden input, and using Javascript to change its value when you check the box.

However, again, the best method here is interpreting it serverside. How is the data being parsed? Are you using a prebuilt script?

In my last post I said this should have been written into the database script
But since it was not, I have to deal with that

do you know some javascript to accomplish what I need? you sound like you know exactly
what I'm faceing

Thanks

PS Yes, it is a prebuilt database.cgi script
the two input values I need to do this with are
input type name="mydatabase" value"db2"
input type name="mytemplate" value"template2"