Solved

Trying tp pass value  from html option select to website

Posted on 2014-01-08
13
370 Views
Last Modified: 2014-01-09
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

0
Comment
Question by:wkrasner
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39766543
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.
0
 
LVL 5

Author Comment

by:wkrasner
ID: 39766558
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
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39766564
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?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39766576
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

0
 
LVL 58

Expert Comment

by:Gary
ID: 39766591
Wouldn't it be easier to just put the values directly in the VALUE of the option?
0
 
LVL 5

Author Comment

by:wkrasner
ID: 39766615
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
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 58

Expert Comment

by:Gary
ID: 39766642
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.
0
 
LVL 5

Author Comment

by:wkrasner
ID: 39767912
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

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39767928
please note ID attribute MUST BE unique in a document unlike class or name attributes.
Also attribute values are case sensitive.

name = "LinkId"
is not
name = "linkid"
or
name = "linkId"

your working and not working code have different name attribute value, the case is different...
0
 
LVL 5

Author Comment

by:wkrasner
ID: 39767998
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

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39768012
"LinkId"
"Linkld"

:(
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39768031
did you saw the difference in my previous comment?
0
 
LVL 5

Author Comment

by:wkrasner
ID: 39768451
thanks.  I am stupid.  it looked like an l to me just changed the font and saw the diff.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now