Solved

Trying tp pass value  from html option select to website

Posted on 2014-01-08
13
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 53

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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
 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

752 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