Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
Results 1 to 1 of 1

Thread: Help needed with form - javascript show div function.

  1. #1
    xert is offline Junior Member
    Join Date
    Feb 2010
    Posts
    1

    Default Help needed with form - javascript show div function.

    Hi folks,

    Hope someone can help. I use a form in our shopping cart which when the form select fields are clicked, the javascript allows information such as a second dropdown form enclosed in a specific div to be revealed to the user. Works fine and here is the javascript code with the body code below ....

    <head>
    <script type="text/javascript">
    window.onload=function() { attachBehaviors(); };
    function attachBehaviors() {
    if (document.getElementById('productpr1')) {
    document.getElementById('productpr1').onchange=fun ction() {
    Display(this,this.selectedIndex);
    };
    }
    }
    function Display(obj,selind) {
    if (! document.getElementById(obj.id)) {
    alert('Oops! Something is not id\'ed correctly ' + obj.id);
    return;
    }
    var divs = Array('a1-div','a2-div');
    var opts = obj.options[selind].value.split(':');
    var div = opts[opts.length-1]; // takes last item, arrays are zero based.
    for (j=0;j<divs.length;j++) {
    if (document.getElementById(divs[j])) {
    document.getElementById(divs[j]).style.display=
    (divs[j]==div)?'block':'none';
    }
    }
    }
    </script>
    </head>
    <body>
    <form action="xxxxx" method="post" name="form1">
    <input type="hidden" name="userid" value="9437628">
    <input type="hidden" name="return" value="xxxx/scripts/cart.php">
    <p style="text-align:center;">Option :
    <input type="hidden" value="1" name="qty1">
    <select name="productpr1" id="productpr1">
    <option selected value="">please select</option>
    <option value="2 seater fabric sofabed:539:a1-div">2 seater fabric sofabed</option>
    <option value="2 seater leather sofa:499:a2-div">2 seater leather sofa</option>
    </select>
    </p>
    <p id="a1-div" style="display:none;text-align:center;">
    <select name="product1[]" id="product1-select">
    <option selected value="">please select</option>
    <option value=", anthracite fabric">fabric : anthracite</option>
    <option value=", beige fabric">fabric : beige</option>
    </select>
    </p>
    <p id="a2-div" style="display:none;text-align:center;">
    <select name="product1[]" id="product2-select">
    <option selected value="">please select</option>
    <option value=", bitter leather">leather : bitter</option>
    <option value=", chestnut leather">leather : chestnut</option>
    </select>
    </p>

    </p>
    </form>
    </body>

    Now what I need to do is allow the script to select multiple divs when a certain option is selected on the first form 'option selected value' field.
    As a working example, this would allow a user to select '2 seater fabric sofabed' and have the options revealed in divs as say 'div id="colour"',
    'div id="delivery"', and 'div id="stainguard"
    Wereas if '2 seater leather sofa' was selected just the first 2 divs would be revealed as stainguard div would not be required.
    Any ideas how I can modify the code to allow this ?
    Kind regards to all.
    Chris
    Last edited by xert; 02-10-2010 at 09:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124