SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Carry two values from drop down menu ?

    Hello!

    Is it possible to someway carry two values from a drop down menu please. I need both the price(example: $79) and the product(example: "1u Cobalt Raq3/4" or "1u Cobalt Raq3/4 $79") sent to then next page.

    Since there are more than one product with the same name in some menus I cant "detect" the product on page 2 based on the price.

    Also...I need the javascript in the code to continue working. (it works fine now, with the a, b, c etc values) It counts the total sum to a textfield at the end.

    For more info, look here please:
    http://sitepointforums.com/showthrea...hreadid=125652

    Example, one of the drop down menus:

    Code:
    	<select name="a" onchange="this.form.summa.value=parseFloat(this[this.selectedIndex].value)+parseFloat(this.form.b[this.form.b.selectedIndex].value)+parseFloat(this.form.c[this.form.c.selectedIndex].value)+parseFloat(this.form.d[this.form.d.selectedIndex].value)+parseFloat(this.form.e[this.form.e.selectedIndex].value)+parseFloat(this.form.f[this.form.f.selectedIndex].value)+parseFloat(this.form.g[this.form.g.selectedIndex].value)+parseFloat(this.form.h[this.form.h.selectedIndex].value)">
    				<option value='79'>1u Cobalt Raq3/4 $79</option> 
    		<option value='79'>1u Cobalt Raq550 $79</option>
    		<option value='99'>1u Cobalt Xtr $99</option>
    		<option value='99'>1u Server other $99</option>
    		<option value='109'>2u Server other $109</option>
    		<option value='139'>4u Server other $139</option>
    	</select>
    Very thankful for help

    (If it helps, the server supports PHP also)

  2. #2
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem is solved, I just put an # in between.

    Example:

    99#1u Cobalt Xtr $99

    Then with PHP I will take out the things before and after the #

    Thanks,

  3. #3
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by developer11
    Thanks
    You’re welcome.
    Of course, that's just my opinion. I could be wrong.

  4. #4
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe.
    Here is how I did it, if anyone need it here.

    'Here the data after the # is taken out
    $myarray1 = explode("#", $a);
    $a = $myarray1[1];

  5. #5
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why dont you use unique ids for your products?

  6. #6
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Volksbad
    why dont you use unique ids for your products?
    Hello!

    Hm...I don't know....how should the code benefit from that please? (and how do I do that)

    Thanks in advance.

    BTW, the code already shipped to client.

  7. #7
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you save your products in a database?

    like this:

    product_id | product_name | product_prize

    1 | Product 1 | 400
    2 | Product 1 | 700
    3 | Product 2 | 100

    now you can use the product_id for option value and you always know your Product and its prize.

    Markus

  8. #8
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha, now I understand what you are heading at.

    No, they are not saved in a database, just sent to the next page and then sent away with an email to the admin.

    Thanks.

  9. #9
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Regarding your initial question:
    Code:
    alert(parseInt('79|1u Cobalt Raq550'))
    alert('79|1u Cobalt Raq550'.split("|"))
    Also, why are you still writing inline code for the onchange event, instead of calling a function?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  10. #10
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know...I am terrible bad at Javascript....

  11. #11
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know...I am terrible bad at Javascript
    Don't know what? And, if the second statement is true, then:
    the code already shipped to client.
    ?

    This is just to show you can access 2 option values from a selection list:
    Code:
    alert(parseInt('79|1u Cobalt Raq550'))
    alert(x=('79|1u Cobalt Raq550'.split("|")))
    alert(x[1] + ' costs $' + parseInt(x[0]))
    The split("...") method takes a string and creates an array based on whatever is placed as its parameter. In the above case, a vertical bar ("|") is used.

    So, you can declare your options as:
    Code:
    <option value='79|1u Cobalt Raq550'>1u Cobalt Raq550</option>
    and use onchange code similar to the one I gave you in the other thread. Or, since you have umpteen thousand selection lists something like this:
    Code:
    <form>
    <select.....>
    .....more select lists...
    <input type='button' value='submit' onclick='doit(this.form)'>
    </form>
    Then you could step through the selection lists and get their selectedIndex values and whatever else in the function itself:
    Code:
    function doit(formObj)
    {
       for (var i = 0; i < formObj.length; i++)
       {
    	  var formEl = formObj.elements[i];
    	  if (formEl.type == 'select')
    	  {
    		  var selObj = formEl[i]
    		  for (var j = 0; j < selObj.length; j++)
    		  {
    			 if(selObj.options[j].selected)
    			   selVal = selObj.options[j].value;
    			   ....code to separate price and item...
    		  }
    	  }
       }
    }
    Note the above is an example, not necessarily code.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •