1

My script code is for ajax function in database. The code is same as below.

 <script>
  function showUser(str)
  {
   .....
  }
  var selectedLang2 = document.getElementById('lang2').value;
  var selectedSubject1 = document.getElementById('subject1').value;
  xmlhttp.open("GET","db_"+selectedLang2+".php?q="+str,true);
 xmlhttp.send();
 } 
 </script>

According to above script code, script code only calls the php file which is selected-option value. So my select-option code is same as below

 <form>
 <select name="lang2" id="lang2">
    <option value="co">한국어</option>
    <option value="en">English</option>

    <option value="af">Afrikaans</option>

    <option value="ar">Arabic</option>
    .......
  </select>
  <select name="subject1" id="subject1">
     <option value="a">Infection : bacteria and virus </option>

     <option value="b">Infection : virus, fungus and etc</option>
     <option value="c">Malignant neoplasm</option>
      ----
  </select>

So I want to use php variables code(here is, $lang1, $subject1) as like below code.

  <?php
  $q = htmlspecialchars($_GET['q']);
  $lang2 = $REQUEST_['lang2'];
  $subject1 = $REQUEST_['subject1'];


  $con = mysqli_connect('localhost','root','autoset','my_db');
  if (!$con)
  ......

How have i to write script code.

 /*Here is target point.
  var selectedLang2 = document.getElementById('lang2').value;
  var selectedSubject1 = document.getElementById('subject1').value;
  xmlhttp.open("GET","db_"+selectedLang2+".php?q="+str,true);
  xmlhttp.send(); */

Please, give me a piece of advice. Thank you

1 Answer 1

0

You can't send any info by GET without specifying the url parameters. But you can add extra parameters to the request url to achieve this.

Change your JS:

var selectedLang2 = document.getElementById('lang2').value;
var selectedSubject1 = document.getElementById('subject1').value;
xmlhttp.open("GET","db_" + selectedLang2 + ".php?q=" + str  + "&lang2=" + selectedLang2 + "&subject1=" + selectedSubject1,true);
xmlhttp.send();

Change your PHP:

$q = htmlspecialchars($_GET['q']);
$lang2 = htmlspecialchars($_GET['lang2']);
$subject1 = htmlspecialchars($_GET['subject1']);
1
  • Really i appreciate your kind reply very much.
    – Drohjho
    Feb 9, 2014 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.