• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Passing Multiple Values with a Drop Down list using javascript?

I am trying to replace a few textboxes and create a dropdown to replace it. I thought that I could do it by passing javascript through with three variables - replacing the text boxes. But this is not working it is telling me that I am not passing through an amount, which I am trying to pass through first.

in the head
function op1(amount,invoice_num,description)
{
return <? print $_REQUEST['amount']; print $_REQUEST['invoice_num']; print $_REQUEST['description'];?>;
}

in the body
<label>
            <select name="select7" id="select7">
              <option value="<script type='text/javascript'>document.write(op1(12.00,100,no description));</script>">Option One</option>
              <option value="<script type='text/javascript'>document.write(op1(24.00,101,no description));</script>" selected>Option Two</option>
              <option value="<script type='text/javascript'>document.write(op1(36.00,102,no description));</script>">Option Three</option>
              <option value="<script type='text/javascript'>document.write(op1(48.00,103,no description));</script>">Option Four</option>
              <option value="<script type='text/javascript'>document.write(op1(60.00,104,no description));</script>">Option Five</option>
              </select>
</label>

I am open to changing this anyway I can get it to work. Please let me know what im doing wrong.
Thanks,
Randy

0
Rabel
Asked:
Rabel
  • 3
  • 3
1 Solution
 
hieloCommented:
look at your browser's source code. What is this giving you?
function op1(amount,invoice_num,description)
{
return <? print $_REQUEST['amount']; print $_REQUEST['invoice_num']; print $_REQUEST['description'];?>;
}

You are mixing SERVER code which runs BEFORE the browser code. So that is definitely causing problems.

Not sure if the attached code is what you actually intended.
function op1(sel)
{
	var val = sel.options[sel.selectedIndex].value
	alert("You selected: " +  val );
return val;
}

in the body
<label>
            <select name="select7" id="select7" onchange="op1(this)">
              <option value="12.00,100,no description">Option One</option>
              <option value="24.00,101,no description" selected>Option Two</option>
              <option value="36.00,102,no description">Option Three</option>
              <option value="48.00,103,no description">Option Four</option>
              <option value="60.00,104,no description">Option Five</option>
              </select>
</label>

Open in new window

0
 
RabelAuthor Commented:
Hi Hielo,
that is close but I need to pass the info to a cart so I need to name the variables -  amount, invoice_num, description. Any Idea how I can do that. Thanks Again.
0
 
hieloCommented:
use hidden variables to send each of them to the server. On the function you just split the value at the commas and assign the corresponding values to the hidden fields.
function op1(sel)
{
        var val = sel.options[sel.selectedIndex].value
       // alert("You selected: " +  val );
	   
	   var data=val.split(",");
	   document.getElementById("amount").value=data[0];
	   document.getElementById("invoice_num").value=data[1];
	   document.getElementById("description").value=data[2];
return val;
}

<label>
            <select name="select7" id="select7" onchange="op1(this)">
              <option value="12.00,100,no description">Option One</option>
              <option value="24.00,101,no description" selected>Option Two</option>
              <option value="36.00,102,no description">Option Three</option>
              <option value="48.00,103,no description">Option Four</option>
              <option value="60.00,104,no description">Option Five</option>
              </select>
</label>
		    <input type="hidden" name="amount" id="amount" value=""/>
		    <input type="hidden" name="invoice_num" id="invoice_num" value=""/>
		    <input type="hidden" name="description" id="description" value=""/>

Open in new window

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
RabelAuthor Commented:
Great Hielo, that works perfect. I will add 100 points if you can explain to me how to get a unique number in the second spot for the invoice_num.
0
 
hieloCommented:
>>how to get a unique number in the second spot
Where are you getting your data from? I thought were were getting these
12.00,100,no description
...
60.00,104,no description

from some database and the invoice_num was an autonumber. So, if you ARE preloading it FROM a db, then you should have an autonumber field and use that as the field.

If you are NOT preloading it, but instead intend TO load/update the db based on the selection, the you should NOT be including that invoice_num in the web form because the invoice number would be auto-generated when you actually insert the record into your db.

If you are NOT using a db at all, then I strongly suggest you do.

Regards,
Hielo
0
 
RabelAuthor Commented:
Thanks Heilo,
I am just using the basic merchant coding that they provided for this small project. I think we will probably only have 20-30 transactions on here. I set it up to use a random number for now.
var randomnumber=Math.floor(Math.random()*100000)
Its not real pretty but I think it should work. What do you think.

This is the info from developer guide, if you can think of anything but you've done enough. I really appreciate your help Heilo.
FIELD NAME - invoice_num
REQUIRED? - Optional
VALUE - The merchant assigned invoice number for the transaction
FORMAT - Up to 20 characters (no symbols)
NOTES - The invoice number must be created dynamically on the merchant server or provided on a per-transaction basis. The payment gateway does not perform this function.

Thanks,
Randy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now