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

LVL 2
RabelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.