Results 1 to 18 of 18
  1. #1
    Join Date
    Feb 2003
    Posts
    62

    How do I give a web form two option values?

    I have a drop down menu form right now that caclulates prices of the things you choose. But I also want a picture to be displayed when you select an option in that form.

    But the only picture display scripts that i've seen are used with option values.

    How can I give something like this two values. Thanks!!!

    <option value="5">TEST</option>

    Oh and I have tried <option value=[5][500] and it doesn't work

  2. #2
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Just give it like value="val1;val2" and split it?
    nu-metal.org :: coming soon

  3. #3
    Why don't you call the function that changes images when you calculate the prices? And use the current value to call the image you want.

    For example, having an array with values like this:

    images[0] = "image1.jpg";
    images[1] = "image2.jpg";
    images[2] = "images3.jpg";
    ...

    so if the selected option value was "2" it would show image3.jpg

    hope this helps

  4. #4
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    No matter what you do that option is only going to give one value to php, javascript, whatever the heck you are using. If you're smart about what that value is you can split it into as many values as you'd like. [5][500] is a valid method, but it's trickier to parse than 5;500. If you want to be tricky you can store information in the id and title attributes as well. Both of these will be accessible from the javascript (though not php).

  5. #5
    Join Date
    Feb 2003
    Posts
    62
    Okay i'm liking the idea of using the same value for picture and calculations variables. Would something like this work?

    <html>
    <head>
    <script type="text/javascript">
    var pics = new Array();
    pics[5] = "test.gif"
    pics[6] = "test2.gif"
    </script>
    </head>

    <script language="javascript">
    var group_prices = new Array(1)
    var group_ship_prices = new Array(1)
    var group_titles = new Array(1)
    var group_vpids = new Array(1)
    var group_pics = new Array(1);

    group_prices[0] = new Array(1);
    group_ship_prices[0] = new Array(1);
    group_titles[0] = new Array(1);
    group_vpids[0] = new Array(1);
    group_pics = new Array(1);

    group_prices[0][0] = 0.0;
    group_ship_prices[0][0] = 0.0;
    group_titles[0][0] = "None";
    group_vpids[0][0] = 0;
    group_pics[0] = "5"

    </script>

    <select onchange="javascript:update_price(this.form,0);"document.getElementById('mypic').src = pics[this.selectedIndex]"
    name="dpsgid_670" class="med" size="1" style="background-color: rgb(0,128,0); background-image: url('images/backtable2.gif'); border: 0px none">

    <option selected value="5">THIS value is used for picture AND calculations</option>
    <option value="6"</option>

  6. #6
    Join Date
    Feb 2003
    Posts
    62
    Welp I just tried the code that I posted there, and the calculations still worked but it wasn't changing the picture

  7. #7
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    Code:
    <select onchange="javascript:update_price(this.form,0);document.getElementById('mypic').src = pics[this.selectedIndex]"
     name="dpsgid_670" class="med" size="1" style="background-color: rgb(0,128,0); background-image: url('images/backtable2.gif'); border: 0px none">
    try replacing your code with the above. There was an extra ' " '

  8. #8
    Join Date
    Feb 2003
    Posts
    62
    Now I just tried another method of splitting the values by doing

    <option value="5;pic.gif">Load pic</option>

    When I selected that value in the form the calculation worked correctly BUT when the picture tried to load, it tried to load 5;pic.gif which means the semi colon didn't really seperate it ...

  9. #9
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    That's because the semi-colon doesn't separate it automatically. Instead you have to split it.

    Code:
    <script>
    
    function doboth($val){
      $splt = $val.split(';');
      doprice($splt[0]);
      dopic($splt[1]);
    
    }
    
    </script>

  10. #10
    Join Date
    Feb 2003
    Posts
    62
    Robeyh I replaced that with what you had but now the calculations don't even work lol.


    I'm now trying a different approach

    <script>
    function picchange(obj)
    {
    if(obj.selectedIndex>0)
    {
    document.images.myimage.style.display="";
    document.images.myimage.src = obj.options[obj.selectedIndex].value;
    }
    else
    {
    document.images.myimage.style.display="none";
    }
    }
    </script>

    group_prices[0][1] = 164.00;
    group_ship_prices[0][1] = 0.0;
    group_titles[0][1] = "TESTing";
    group_vpids[0][1] = 5;


    <select onchange=picchange(this);javascript:update_price(this.form,0); name="dpsgid_670" class="med" size="1" style="background-color: rgb(0,128,0)">

    <option selected value="0">Please Select</option>
    <option value="image.gif</option>
    </select>

    Now because in my calculations variables it shows exactly what form does the calculations, I do not need the option value in the form itself. I actually got it to partially work. When I selected the option for the first time loading the page, the picture loaded and data was calculated WOHOO!!! but as soon as I unselected and reselected the data was being gathered by the variables meaning it now tried to load this: http://blahlbah....5;

    group_vpids[0][1] = 5;

    SO!! This means that if I can figure out how to split not the option values in the form, but this value here then i'll be able to do it. I need something like this.

    group_vpids[0][1] = 5; picture.gif

    But I know once I do that it will screw up my calculations.

  11. #11
    Join Date
    Feb 2003
    Posts
    62
    AHHH disregard my last message there you reply way too fast lol let me try that seperation script

  12. #12
    Join Date
    Feb 2003
    Posts
    62
    okay robe even with the script you showed me the ; did not seperate it and still tried to load 5;pic.gif instead of just pic.gif

    Oh well i'm about to give up, i've tried just about everything and i'm too much of a noob to really fix this.

  13. #13
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    Try this.. then modify to suit.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function doboth($vars){
        //$vars = $vars.elements.namedItem('dpsgid_670').value;
        $vars = $vars.value;
        $splt = $vars.split(';');
        update_price($splt[0]);
        update_pic($splt[1]);
    }
    
    function update_price($p){
        document.getElementById('price').value = $p
    }
    
    function update_pic($p){
         document.getElementById('pic').value = $p
    }
        
    </script>
    </head>
    
    <form>
    <select onchange="javascript:doboth(this);" name="dpsgid_670" class="med" size="1" style="background-color: rgb(0,128,0); background-image: url('images/backtable2.gif'); border: 0px none">
    
    <option selected value="5;pic1.jpg">THIS value is used for picture AND calculations</option>
    <option value="6;pic2.jpg"></option>
    </select>
    <input id="price" />
    <input id="pic" />
    </form>
    </body>
    </html>

  14. #14
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Since when does JavaScript use '$' for variables?
    nu-metal.org :: coming soon

  15. #15
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    since I've been programming in php too long. What's great though is that it works... as opposed to doing it the other way around...

  16. #16
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    I don't think you should use $ in variable names, and you should define variables using 'var ...'
    nu-metal.org :: coming soon

  17. #17
    Join Date
    Mar 2004
    Location
    Granville OH
    Posts
    108
    Indeed I shouldn't. It was a mistake. I don't program in php all too often, but I was forced to do a lot of it today. And I rarely code in javascript... server side is much more reliable. Just be glad I wasn't in python mode. And yes, as it was a local variable I should have used var.

  18. #18
    Join Date
    Feb 2003
    Posts
    62
    Okay I cannot seem to fix this. I am a noob and am having lots of trouble. If you want to look at the full working calc go here:

    http://www.geocities.com/darkhelmet6...SALEPRICES.htm

    If you think that you could easily install the picture option into one of those forms then give me a PM maybe we can work out a deal.

Posting Permissions

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