0

I have multiple forms in same php page. I am able to show and hide them based the drop down value selected But I have a variable called $url i want to have different value when each form loads

     <script>
      function validate(){
      var first = document.getElementById("first");
      var first-val = first.options[first.selectedIndex].value;
      var second = document.getElementById("seconed");
      var secondval = second.options[second.selectedIndex].value;

if(first-val == "Rear Tire" && secondval ==  "2WD")
{
document.getElementById("RA").style.display="";
document.getElementById("RB").style.display="none";
 var test = '<?php $url ="reartire"?>
} 

else if(first-val == "Rear Tire" && secondval ==  "MFWD")
   {
    document.getElementById("RA").style.display="none";
    document.getElementById("RB").style.display="";
   var test = '<?php $url ="fronttire"?>
   }

I tried adding

Inside the the first if - var test = '<?php $url ="yahoo.com"?>';

For the second if i added if- var test = '<?php $url ="google.com"?>'; But it only sees the the value of $url inside the second if

Kin
  • 145
  • 1
  • 11
  • What does the title mean? Using what? – Pointy May 04 '16 at 19:38
  • There are some serious grammatical issues in this question. Did you run this through google translate? That doesn't work. Furthermore you can't mix and match the `$url=`. It's going to assign that regardless of whether or not it hits the conditional, because PHP interprets the page top down. – Ohgodwhy May 04 '16 at 19:39
  • @Ohgodwhy Sorry for the grammer and Typo. thanks. what is the best way to handle this? – Kin May 04 '16 at 19:47
  • `$url` is a PHP variable, not a JavaScript variable. – Quentin May 04 '16 at 19:51
  • var test = ' <---You're missing a single quote and a semicolon here as well. var test = ' <---And here. – Dresden May 04 '16 at 19:56

1 Answers1

0

Problem may be in the value assignment of test in js using php. Either use php short tag or echo the php variable when assigning php variable/value to a js variable.

Deb K. Das
  • 27
  • 6