0

1)The user will click the button after each list. 2)onclick the button will send the selected value to a javascript function 3)I want to take the value in the javascript function and send to a php file using ajax

Question How do I send html selected value to a javascript function using onclick?

<select id="list"> 
      <option value=" ">Select a Name </option>
      <option value="Comfy">Comfy</option>
      <option value="Tough">William Tough </option>
      <option value="Soft">Soft</option>
</select>
<button onclick="updateDB(this.querySelector('list'.selected))">Click Me</button>

<select id="list2"> 
      <option value=" ">Select a Name </option>
      <option value="Comfy">Comfy</option>
      <option value="Tough">William Tough </option>
      <option value="Soft">Soft</option>
</select>
<button onclick="updateDB(this.querySelector('list2'.selected))">Click Me</button>

Javascript function:

function updateDB(number)
{

 if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
} else {
    // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

    xmlhttp.open("GET","/updatequery.php?numbers",true);
xmlhttp.send();
}
6
  • $resultset = oci_execute($stid2); var_dump($resultset); Commented Nov 4, 2016 at 15:19
  • @Cagy79 oci_execute() returns bool. @Nameishi Check examples for how to fetch php.net/manual/en/function.oci-execute.php. Did you look anywhere before asking? Commented Nov 4, 2016 at 15:21
  • @AbraCadaver Correct! Commented Nov 4, 2016 at 15:24
  • 1
    oci should be for oracle not for mysql .. remove improper tag and add the right one Commented Nov 4, 2016 at 15:24
  • $resultset = oci_execute($stid2); tells me invalid character Commented Nov 4, 2016 at 15:25

1 Answer 1

3

Check the PHP documentation on OCI: http://php.net/manual/en/function.oci-execute.php

You need to fetch the rows from the database once you executed the select query.

An example here that should get you started:

<?php

$conn = oci_connect('hr', 'welcome', 'localhost/XE');

$stid = oci_parse($conn, 'SELECT * FROM employees');
oci_execute($stid);

echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

?>
Sign up to request clarification or add additional context in comments.

4 Comments

So you have to use a loop ? even if the outcome is just one element?
@Nameishi: No, you don't.
@AbraCadaver could I use $data2 = array(); $result = oci_fetch_all($stid, $data2, null, null, OCI_FETCHSTATEMENT_BY_ROW);
@AbraCadaver can you send me a link that would help? point me in right direction please

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.