0

I want to get three values from a MYSQL table, and display them in a text area. I can get only one value. If it possible, I want to save this selector, because it is critical to my program.

JavaScript:

function getsteel() {
  var material = document.getElementsByName("option");
  if (material[3].checked == true) {
    var g = document.getElementById("selector1");
    var str = g.options[g.selectedIndex].value;
    document.getElementById('kr').value = str;
  }
}

HTML:

<td>k<sub>r</td></sub>
 <td>
    <input type="text" id="kr" disabled style="width:50px;">
  </td>
  <td>[MPa]</td>

PHP:

<?php
mysql_connect("localhost","root","");
mysql_select_db("db-user22777");
//query
$sql=mysql_query("SELECT * FROM steels ORDER BY id ASC");
if(mysql_num_rows($sql)){
  $select= '<select id="selector1" disabled size="12">';
  while($r=mysql_fetch_array($sql)){
    $select.='<option value="'.$r['kr'].'">'.$r['Steelname'].' | '.$r['kr'].' [MPa]</option>';
  } 
}
$select.='</select>';
echo $select;
?>

Thanks for any help provided!

jsanchezs
  • 1,992
  • 3
  • 25
  • 51
  • 3
    If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Mar 05 '17 at 18:58
  • [Don't add fake tags to your title](https://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles). The real tags attached to your question are what's important. – ChrisGPT was on strike Mar 05 '17 at 18:58
  • @Chris we should template your comment . – hassan Mar 05 '17 at 20:03

0 Answers0