Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Location
    Holland
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Javascript for a seemingly simple radio button question

    Dear forum members,

    I'm fairly new at Javascripting for I'm not a programmer but a designer.

    For my employer I've made several fillable forms in Adobe Acrobat X to fill in by our customers (firstly in InDesign though and then exported to be edited in Acrobat). All include various Javascripts which I found online. So I understand the basics and recognize elements of scripting, but unfortunately this doesn't suffice for me to be able to solve my current problem.

    My problems about a group of 3 radio buttons (a group called rb1), each one accompanied by it's own text box containing a price and an empty text box as well. Radio button 1 (choice1) stands for 149 euros, radio button 2 (choice2) for 249 euros and radio button 3 (choice3) for 499 euros. If radio button 1 is selected, empty text field number 1 (prijs1b) should show 149 and the rest of course 0, because you can only select one radio button at a time. If the second radio button (choice2) is selected text field number 2 (prijs2b) should show 249 et cetera. Look at the image to get a better idea of what I mean.



    Can anybody help me please? I've strolled down so many websites to find an answer, but it's nowhere to be found.

    Thanks a lot in advance!

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by Viriidaoutlaw View Post
    Dear forum members,
    I'm fairly new at Javascripting for I'm not a programmer but a designer.
    For my employer I've made several fillable forms in Adobe Acrobat X to
    fill in by our customers . All include various Javascripts which I found online.
    The solution is simple, ask your employer
    to hire a competent programmer. Many
    can be found in the
    Web Projects and Services Marketplace
    section of this site.

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,148
    Thanks
    39
    Thanked 506 Times in 500 Posts

    Lightbulb

    Can't read your language, so obviously, changes are necessary...

    I'm not sure what you are trying to do with the picture, so this is just a guess.
    See if you can modify this to your needs...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> Untitled </title>
    
    </head>
    <body>
    <form method="post" action="" onsubmit="return false">
    <table id="tbl" border="1">
     <tr>
      <td><input type="radio" id="rb00" name="rb1" value="149" onclick="fillFiliaal(this)"> 1 filiaal</td>
      <td><input type="text" id="item00" value=""></td>
      <td><input type="text" id="item01" value=""></td>
     </tr>
     <tr>
      <td><input type="radio" id="rb01" name="rb1" value="249" onclick="fillFiliaal(this)"> 2 to 5 filiaal</td>
      <td><input type="text" id="item10" value=""></td>
      <td><input type="text" id="item11" value=""></td>
     </tr>
     <tr>
      <td><input type="radio" id="rb02" name="rb1" value="499" onclick="fillFiliaal(this)"> 6 or more filiaal</td>
      <td><input type="text" id="item20" value=""></td>
      <td><input type="text" id="item21" value=""></td>
     </tr>
     <tr>
      <td><button onclick="clrItems()"> Clear </td>
      <td>&nbsp;</td>
      <td><input type="text" id="itemTotals" value=""></td>
     </tr>
    </table>
    </form>
    
    <script type="text/javascript">
    function clrItems() {
      var sel = document.getElementById('tbl').getElementsByTagName('input');
      for (var i=0; i<sel.length; i++) {
        if (sel[i].type == 'text') { sel[i].value = ""; }
      }
    }
    
    function fillFiliaal(T) { 
      clrItems();
      switch (T.id) {
        case 'rb00' : document.getElementById('item00').value = T.value;
                      document.getElementById('item01').value ='';  break;
        case 'rb01' : document.getElementById('item10').value = T.value;
                      document.getElementById('item11').value = '';  break;
        case 'rb02' : document.getElementById('item20').value = T.value;
                      document.getElementById('item21').value = '';  break;
      }
    }
    </script>
    
    </body>
    </html>
    Keep in mind that on most forums, you get what you pay for.
    Without further definition and requirements, this is just my 2 cents worth.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,313
    Thanks
    203
    Thanked 2,564 Times in 2,542 Posts
    filiaal means branch offfice/shop (of a business).
    eenheidsprijs means unit price.
    totaalprijs means total price.
    uwjaartarief means your annual payment.

    jmrker's code is fine but I do not see the point of the total price column. A business cannot have both 1 and 2-5 branches.

    Label on Tesco Norwegian Fir Christmas Tree:- Unsuitable for human consumption.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Dec 2013
    Location
    Holland
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi jmrker,

    Thanks for your reply. The language in the screenshot is Dutch, so no wonder that you don't understand it. However, I think you don't need to, to be able to come up with the solution to my problem.

    Unfortunately I think I might not be able to use your code at all because it contains html. I only need the correct Javascript for setting up the right actions. This is because I'm making a pdf form, not a web form. Adobe Acrobat doesn't support the use of html. So I think you misunderstood my question.

    In other pdf forms I succesfully created I have used codes like the one below:

    if (this.getField("rb1").value!="Choice1") this.getField("prijs24b").value = 0;
    if (this.getField("rb1").value!="Choice2") this.getField("prijs24b").value = this.getField("prijs24a").value;

    The code above works in another form I created. In the picture below you see a screenshot of a relevant part of this form:

    http://www.aca.nl/images/fullsize/javascript2.jpg

    The grey screen on the left of the image is a properties window from Adobe Acrobat for entering the Javascript; in this case a so called adapted calculation script ('aangepast berekend script'). It works like this: when I fill in 'Ja' in any one of the rows, then the price in the 'a' price column is copied into the 'b' price column. If 'Nee' is selected (this is the standard setting), then nothing is filled in in this column as you can see.

    However, when I try to use it in a form with more than 2 choice rounds, it doesn't seem to work anymore.

    @Philip M: Were you raised bilingual or did you just use a translator program? :P I think you're right. The total price field doesn't really have any added value. So I think I will remove it from the form. First I have to get the d@#n thing to work.

    Thanks in advance again for your help!

  • #6
    New to the CF scene
    Join Date
    Dec 2013
    Location
    Holland
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Clarification of the problem

    Thanks for your reply jmrker. The language in the screenshot is Dutch, so no wonder that you don't understand it. However, I think you don't need to, to be able to come up with the solution to my problem.

    Unfortunately I think I might not be able to use your code at all because it contains html. I only need the correct Javascript for setting up the right actions. This is because I'm making a pdf form, not a web form. Adobe Acrobat doesn't support the use of html. So I think you misunderstood my question.

    In other pdf forms I succesfully created I have used codes like the one below:

    if (this.getField("rb1").value!="Choice1") this.getField("prijs24b").value = 0;
    if (this.getField("rb1").value!="Choice2") this.getField("prijs24b").value = this.getField("prijs24a").value;

    The code above works in another form I created. In the picture below you see a screenshot of a relevant part of this form:

    http://www.aca.nl/images/fullsize/javascript2.jpg

    The grey screen on the left of the image is a properties window from Adobe Acrobat for entering the Javascript; in this case a so called adapted calculation script ('aangepast berekend script'). It works like this: when I fill in 'Ja' in any one of the rows, then the price in the 'a' price column is copied into the 'b' price column. If 'Nee' is selected (this is the standard setting), then nothing is filled in in this column as you can see.

    However, when I try to use it in a form with more than 2 choice rounds, it doesn't seem to work anymore.

    @Philip M: Were you raised bilingual or did you just use a translator program? :P I think you're right. The total price field doesn't really have any added value. So I think I will remove it from the form. First I have to get the d@#n thing to work.

    Thanks in advance again for your help!


  •  

    Tags for this Thread

    Posting Permissions

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