Results 1 to 8 of 8

Thread: Submiting two inputs using one checkbox

  1. #1
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Submiting two inputs using one checkbox

    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

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    You could just send the value through an hidden input.

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

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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; }
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Medyman View Post
    You could just send the value through an hidden input.

    Code:
    <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

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    As I said, do this AFTER the form is submitted. One checkbox, one value. But then two reactions.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    doester (04-07-2008)

  7. #6
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    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

  8. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #8
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    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"
    Last edited by doester; 04-07-2008 at 04:03 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •