Link to home
Start Free TrialLog in
Avatar of Needy11
Needy11

asked on

jscript if statement

I need to redirect to a differnt thank you page at the end of a booking process based on a variable called yes_no. The variable is displayed fine in the HTML see fist line with %yes_no% and displays as 'yes' on the final page but when I try to convert this to a form that can be used in javascript I cannot get the variable to be assigned this value correctly. Anyone know the syntax I should be using. See below for what I have tried...

Tx Ciaran

body
{
	font-family:Arial, sans-serif;
	line-height:1.5em;
	background-color:transparent
}
      </style>
      <meta name='GENERATOR' content='MSHTML 9.00.8112.16448'/>
   </head>
   <body >
      <div >%yes_no%</div>
      <div >&nbsp;</div>
      <div >

<script type="text/javascript">
var paymethod;
var test2 = "Test2";
window.alert(test2);


paymethod = %yes_no%;
window.alert(paymethod);

if (paymethod == "yes")
{
window.alert("Paypal");
  document.write("Paypal");
}
else
{
window.alert("Invoice");
 document.write("Invoice");
}

</script>

Open in new window

SOLUTION
Avatar of tlayton
tlayton
Flag of South Africa 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 Needy11
Needy11

ASKER

Unfortuantely that didn't work.

Here is the webpage if thats any help....

http://elearning.ahead.ie/forms/signup/signup.php
SOLUTION
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 Needy11

ASKER

No worries. I tried assigning paymethod with both document.getElementById('YesNo').val();  and document.getElementById('YesNo').innerhtml(); but the value didn't take even though it displays as innerhtml.

Any ideas why? - http://elearning.ahead.ie/forms/signup/signup.php 


<script type="text/javascript">
var paymethod = document.getElementById('YesNo').innerhtml(); 
var test2 = "Test2";
window.alert(test2);

window.alert(paymethod);

if (paymethod == "yes")
{
window.alert("Paypal");
  document.write("Paypal");
}
else
{
window.alert("Invoice");
 document.write("Invoice");
}

Open in new window

ASKER CERTIFIED SOLUTION
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 Needy11

ASKER

Thanks for that () removed. Any idea why paymethod var is undefined though. I have assigned it's value and defined it.

Tx

Ciaran
Avatar of Needy11

ASKER

Its ok I used textContent property instead and it works!! Thanks you.

Ciaran