Lijst waarde als input veld gebruiken

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Yves Robeyst

Yves Robeyst

02/04/2013 18:00:16
Quote Anchor link
Op een webpagina ik een lijst met daarin alle klantnamen (Recordset van een MySQL tabel). In deze lijst zijn de labels de klantnamen en de values (niet zichtbaar) de klantennummer.

Nu wens ik dat bij het selecteren van een klantnaam (klikken) de klantennummer ([ID] verschijnt in het ingaveveld [Klantid]. Verder met de andere ingavevelden kan dat een nieuwe record worden aangemaakt in een andere MySQL table (insert record]

Mijn vraag is nu hoe ik de waarde uit de lijst kan doen verschijnen in het ingaveveld of in andere gevallen verzenden naar andere queries.

Hieronder mijn huidig script.
Alvast bedankt voor jullie reacties

[
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php require_once('Connections/myconnection.php'); ?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
if (!function_exists("GetSQLValueString")) {
function
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{

  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }


  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case
"text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case
"long":
    case
"int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case
"double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case
"date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case
"defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }

  return $theValue;
}
}


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form3")) {
  $insertSQL = sprintf("INSERT INTO opdrachtfiche (Opdrachtid, Klantid, Opdracht, Creatiedatum, Deadline, omschrijving, Status) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Opdrachtid'], "int"),
                       GetSQLValueString($_POST['Klantid'], "int"),
                       GetSQLValueString($_POST['Opdracht'], "text"),
                       GetSQLValueString($_POST['Creatiedatum'], "date"),
                       GetSQLValueString($_POST['Deadline'], "date"),
                       GetSQLValueString($_POST['omschrijving'], "text"),
                       GetSQLValueString($_POST['Status'], "text"));

  mysql_select_db($database_myconnection, $myconnection);
  $Result1 = mysql_query($insertSQL, $myconnection) or die(mysql_error());
}


mysql_select_db($database_myconnection, $myconnection);
$query_klantenselectie = "SELECT * FROM klanten ORDER BY Firmanaam ASC";
$klantenselectie = mysql_query($query_klantenselectie, $myconnection) or die(mysql_error());
$row_klantenselectie = mysql_fetch_assoc($klantenselectie);
$totalRows_klantenselectie = mysql_num_rows($klantenselectie);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>opdracht</title>

<style type="text/css">
.lijst {
width: 400px;
background-color: #F90;
visibility: visible;
}
.label {
position: relative;
}
.hoofding {
font-family: "Comic Sans MS", cursive;
font-size: 24px;
color: #F90;
}
.label {
font-size: 18px;
color: #F90;
}
</style>
</head>

<body>
<p align="center" class="hoofding">CREATIE OPDRACHTFICHE
</p><form id="form2" name="form2" method="post" action="browse">
<div align="center">
<table width="73%" border="0">
<tr>
<td width="31%"><img src="opdracht.jpg" width="207" height="144" /></td>
<td width="24%"><div align="right">Selecteer een klant : </div></td>
<td width="45%"><select name="Klanten" size="5" class="lijst" id="Klanten" >
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
do {  
?>

<option value="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo $row_klantenselectie['ID']?>
">
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo $row_klantenselectie['Firmanaam']?>
</option>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?php
} while ($row_klantenselectie = mysql_fetch_assoc($klantenselectie));
  $rows = mysql_num_rows($klantenselectie);
  if($rows > 0) {
      mysql_data_seek($klantenselectie, 0);
      $row_klantenselectie = mysql_fetch_assoc($klantenselectie);
  }

?>

</select></td>
</tr>
</table>
</div>
</label>
</form>
<form action="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo $editFormAction; ?>
" method="post" name="form3" id="form3">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Opdrachtid:</td>
<td><input type="text" name="Opdrachtid" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Klantid:</td>
<td><input name="Klantid" type="text" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Opdracht:</td>
<td><input type="text" name="Opdracht" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Creatiedatum:</td>
<td><input type="text" name="Creatiedatum" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Deadline:</td>
<td><input type="text" name="Deadline" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Omschrijving:</td>
<td><input type="text" name="omschrijving" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Status:</td>
<td><input type="text" name="Status" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form3" />
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
mysql_free_result($klantenselectie);
?>

]
 
PHP hulp

PHP hulp

26/04/2024 21:58:54
 
Frank Nietbelangrijk

Frank Nietbelangrijk

02/04/2013 19:34:10
Quote Anchor link
wil je alsjeblieft even de code tussen [ c o d e ] en [ / c o d e ] zetten (maar dan zonder spaties)
ook kun je de CSS er makkelijk uitlaten daar je vraag over php/mysql gaat.




Toevoeging op 02/04/2013 20:03:10:

dat hele gedoe met do/while kun je versimpelen tot:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
<?php
$query
= "SELECT * FROM klanten ORDER BY Firmanaam ASC";
$klantenselectie = mysql_query($query, $myconnection); // ZONDER die()!
echo '<select>';
while($row = mysql_fetch_assoc($klantenselectie))
{

  echo '<option value="'.$row['ID'].'">'.$row['Firmanaam'].'</option>';
}

echo '</select>';
?>


Toevoeging op 02/04/2013 20:33:33:

dan als er een klant geselecteerd wordt in de dropdown dan moet daar een actie op plaatsvinden in de browser. PHP draait op de server, javascript in de browser. Dus moet dit met Javascript.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<head>
<script>
window.onload = function() {
    var input = document.getElementById('klantid');
    var select = document.getElementById('klantenlijst');
    
    input.value = select.options[0].value;
    
    select.onchange = function() {
        input.value = this.options[this.selectedIndex].value;
    }
}
</script>
</head>
<body>
<select id="klantenlijst">
    <option value="1">klant 1</option>
    <option value="2">klant 2</option>
</select>
<input id="klantid" />
</body>
</html>
Gewijzigd op 02/04/2013 20:06:24 door Frank Nietbelangrijk
 
Yves Robeyst

Yves Robeyst

03/04/2013 14:39:28
Quote Anchor link
Het simpeler PHP script is me duidelijk. Maar het javascript zorgt er niet voor dat mijn veld 'klantid' wordt ingevuld. Ook hetgeen in de body wordt geplaatst is me volkomen onduidelijk. Wat voor nut heeft dit ?
Kan je hier meer uitleg rond geven ? Bedankt
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.