Link to home
Start Free TrialLog in
Avatar of Rabel
Rabel

asked on

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

Avatar of hielo
hielo
Flag of Wallis and Futuna image

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

Avatar of Rabel
Rabel

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rabel

ASKER

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.
>>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
Avatar of Rabel

ASKER

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