[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript Not Adding

Posted on 2014-08-21
9
Medium Priority
?
148 Views
Last Modified: 2014-08-28
I have the following script that grabs a input field value:
<script>
	var myBox8 = document.getElementById('addon-28-bicycle-info[association-membership-1]').value;

		<?php
			$assoc = $pdo->prepare($association);
						
			try {
				$assoc->execute();
				$ass = $assoc->fetchAll();
			
				foreach ($ass as $as)	{
					$app = $as->physical_damage;	
				}
			}
			catch(PDOException $b) {
   				echo 'ERROR: ' . $b->getMessage();
			}	
		?>	
		if(myBox8 == 'yes' ) { myBox9 = <?php echo $app; ?> }
		else { myBox9 = 1 }

Open in new window

When it renders it looks like this:
var myBox8 = document.getElementById('addon-28-bicycle-info[association-membership-1]').value;
if(myBox8 == 'yes' ) { myBox9 = 0.90 }
else { myBox9 = 1 } 

Then I have:
var myResult = parseFloat(myResultSub) * parseFloat(myBox9);

myBox9  always uses 1 even though  the value of myBox8 is "yes"

Open in new window


What else do I need to supply so you can help me solve thbis issue?
0
Comment
Question by:rgranlund
  • 4
  • 4
9 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40277150
Are you sure myBox8 = 'yes' exactly?
What happens if you add an alert for myBox8? Does it alert yes
0
 

Expert Comment

by:mervint
ID: 40277302
Is association-membership-1  a variable? Then move it outside the quotes
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40277437
Yes, myBox8 alerts 'yes'.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 58

Expert Comment

by:Gary
ID: 40277494
Can you post the rendered HTML of the addon-28-bicycle-info element - is this something the user enters or is already filled in

Here's your code exactly as you have it and it alerts 0.9
http://jsfiddle.net/GaryC123/3tqs77m4/2/
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40277575
<select name="addon-28-bicycle-info[association-membership-1]" id="addon-28-bicycle-info[association-membership-1]" onchange="findSum()" >

						<option>Association Membership</option>

						<option value="yes">Yes</option>

						<option value="no">No</option>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40277598
Your code and I still get 0.9

http://jsfiddle.net/GaryC123/3tqs77m4/3/
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40277690
If you go here, and go through the process and pay attention to association membership and then hit add to cart, you see it does not stick:
http://spokeinsurance.com/index/
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40277758
Change
var myBox8 = document.getElementById('addon-28-bicycle-info[association-membership]').value;

Open in new window

to
var myBox8 = jQuery('[id*="association-membership"]').val()

Open in new window

0
 
LVL 7

Author Comment

by:rgranlund
ID: 40277953
Still no go.  Thanks for all of your help.  I don't want to waste your time with my mess.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month18 days, 7 hours left to enroll

825 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