Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

Javascript Not Adding

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?
Avatar of Gary
Gary
Flag of Ireland image

Are you sure myBox8 = 'yes' exactly?
What happens if you add an alert for myBox8? Does it alert yes
Avatar of mervint
mervint

Is association-membership-1  a variable? Then move it outside the quotes
Avatar of Robert Granlund

ASKER

Yes, myBox8 alerts 'yes'.
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/
<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

Your code and I still get 0.9

http://jsfiddle.net/GaryC123/3tqs77m4/3/
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/
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland 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
Still no go.  Thanks for all of your help.  I don't want to waste your time with my mess.