Link to home
Start Free TrialLog in
Avatar of Will
WillFlag for United States of America

asked on

Trying tp pass value from html option select to website

Trying to pass xxxxx or yyyyy  depending upon option selected.  just doing the post with out the option works fine.  

like this
<input type = "hidden" name = "LinkId" value ="xxxxx" />

Trying to us the following.  I know I am doing something stupid. thanks

<script type="text/javascript">
function changeValue(){
    var option=document.getElementById('linkld').value;

    if(option=="A"){
            document.getElementById('field').value="xxxxx";
    }
        else if(option=="B"){
            document.getElementById('field').value="yyyyy";
        }

}
</script>
</head> 
<body> 



<form name="PrePage" method = "post" action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">		

		<select name="linkld" id="linkld" onchange="changeValue();">
                	  <OPTION Value="A">Single Person Household - $20.00</OPTION>
                    <OPTION value="B">2 Person Household - $30.00</OPTION>
                    
                </SELECT>
				
							
				<input type = "text" name = "linkld" ID="field" value="" />
		<input type="submit" value="Add to Cart"/>	
	</form>		

Open in new window

Avatar of Tom Beck
Tom Beck
Flag of United States of America image

var options=document.getElementById('linkld').options;

Will get you an array of the options in the select block.

Loop through them to look for option "A" or "B" value.
Avatar of Will

ASKER

Thank you not sure I follow you.  My question is not on the Java side but rather on the html side  I can get the xxxxx or yyyy to appear in a text box  but doesn't pass to the post using a hidden
Your js had an extra curly bracket
   var option=document.getElementById('linkld').value;

    if(option=="A"){
   
            document.getElementById('field').value="xxxxx";
    }
        else if(option=="B"){
            document.getElementById('field').value="yyyyy";
        }

Open in new window


Are you trying to pass a request form to javascript?  Or just trying to have the javascript detect what is selected by changing the option or clicking a button?
Check this : http://jsfiddle.net/KSXt5/1/

function changeValue(option){
    if(option=="A") document.getElementById('field').value="xxxxx";
    else
    if(option=="B") document.getElementById('field').value="yyyyy";
}

Open in new window


I updated the onchange attribute :
<form name="PrePage" method = "post" action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">		
    <select name="linkld" id="linkld" onchange="changeValue(this.value);">
        <option>Choose one</option>
        <OPTION value="A">Single Person Household - $20.00</OPTION>
        <OPTION value="B">2 Person Household - $30.00</OPTION>
     </select>
    <input type="text" name = "linkld" ID="field" value="" />
    <input type="submit" value="Add to Cart"/>	
</form>	

Open in new window

Wouldn't it be easier to just put the values directly in the VALUE of the option?
Avatar of Will

ASKER

Cathal

That's exactly what I want to do, how would I? I need to pass the selected value as a hidden type input?

also the input line I am using is:

<input type = hidden" name = "linkld" ID="field" value="" />

not what I have above.  Above just returns xxxx or yyyy into the text box
Instead of
<OPTION Value="A">Single Person Household - $20.00</OPTION>

why not have it there to start with i.e.

<OPTION Value="xxxx">Single Person Household - $20.00</OPTION>

and get rid of the javascript and the hidden field

I'm confused why you have two elements (the dropdown and the hidden field) with the same name linkld if you are only wanting to pass one value.
Avatar of Will

ASKER

This is what I am trying to Use,  without the Javascript.  But is doesn't pass the value

<form name="PrePage" method = "post" action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">		
    <select name="linkld" id="linkld" >
        <option>Choose one</option>
        <OPTION value="6e6f6b1c-7d13-4a99-b8ab-e2791884aae6">Single Person Household - $20.00</OPTION>
        <OPTION value="8d8bf5a3-aab1-442e-8869-6741639e421c">2 Person Household - $30.00</OPTION>
     </select>
       <input type="submit"  id="linkld" value="Add to Cart"/>	
</form>	

Open in new window


The following is the syntax that does work with a button rather than an select option:

01.
<form name="PrePage" method = "post" action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx"> <input type = "hidden" name = "LinkId" value ="6e6f6b1c-7d13-4a99-b8ab-e2791884aae6" /> <input type = "image" src ="//content.authorize.net/images/buy-now-gold.gif" /> </form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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 Will

ASKER

Thank you.  I have made the changes as follows.  Still doesn't work.
<form name="PrePage" method = "post" action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">		
    <select name="Linkld" id="Linkldx" >
        <option>Choose one</option>
        <OPTION value="6e6f6b1c-7d13-4a99-b8ab-e2791884aae6">Single Person Household - $20.00</OPTION>
        <OPTION value="8d8bf5a3-aab1-442e-8869-6741639e421c">2 Person Household - $30.00</OPTION>
     </select>
       <input type="submit"   value="Add to Cart"/>	
</form>	

Open in new window

"LinkId"
"Linkld"

:(
did you saw the difference in my previous comment?
Avatar of Will

ASKER

thanks.  I am stupid.  it looked like an l to me just changed the font and saw the diff.