Results 1 to 5 of 5

Thread: How do I repeat this code

  1. #1
    Join Date
    Apr 2014
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default How do I repeat this code

    Hi,

    I have a jsfiddle which I have seen off another site.

    http://jsfiddle.net/XssCG/307/

    It does the job perfectly, but I want to use the same code four or five times. So in one form use this Yes/No drop down list and depending on the answer the other drop lists become available.

    Just so it's clear I want the exact same as I have but a repeat of it.

    How do I do this?

    I've tried so many different ways, I just can't work it out

    Thank you

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    As long as you keep to the format of a unique id with no number for the yes/no select and that same id with the number 1 added at the end for the select that it is to control, this will do it:

    Code:
    function check(elem) {
        document.getElementById(elem.id + '1').disabled = !elem.selectedIndex;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2014
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your reply, I couldn't get it to work though

    http://jsfiddle.net/XssCG/311/

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Id's must be unique and follow the pattern this works:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    function check(elem) {
        document.getElementById(elem.id + '1').disabled = !elem.selectedIndex;
    }
    </script>
    </head>
    <body>
    <form>
    <select id="mySelect" onChange="check(this);">
    <option>Yes</option>
    <option>No</option>
    </select>
    
    <select id="mySelect1" disabled="disabled" >
             <option value=" "> </option>
              <option value="Claim on hold">Claim on hold</option>
              <option value="No reference available">No reference available</option>
              <option value="Customer cancelled claim">Customer cancelled claim</option>
    </select>
        <select id="mySelect2" onChange="check(this);">
    <option>Yes</option>
    <option>No</option>
    </select>
    
    <select id="mySelect21" disabled="disabled" >
             <option value=" "> </option>
              <option value="Claim on hold">Claim on hold</option>
              <option value="No reference available">No reference available</option>
              <option value="Customer cancelled claim">Customer cancelled claim</option>
    </select>
    </form>
    
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    padders01 (05-16-2014)

  6. #5
    Join Date
    Apr 2014
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    That brilliant, thanks for your help

Similar Threads

  1. Help with Jquery code repeat
    By mulaus in forum JavaScript
    Replies: 3
    Last Post: 03-23-2013, 06:27 PM
  2. Resolved Repeat Y problem in IE
    By ModernRevolutions in forum HTML
    Replies: 1
    Last Post: 01-17-2009, 11:30 AM
  3. Replies: 4
    Last Post: 11-22-2008, 08:42 PM
  4. Css background repeat x
    By Alidad in forum CSS
    Replies: 1
    Last Post: 01-07-2008, 03:08 PM
  5. Why does my script repeat once ????
    By pcbrainbuster in forum JavaScript
    Replies: 37
    Last Post: 02-28-2007, 07:17 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
  •