ausgewähltes select auslesen

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • ausgewähltes select auslesen

    Hallo,

    wie die Überschrift schon sagt will ich ein Select auslesen undzwar habe ich mehre Selects

    nun hab ich das mit form geregelt

    Source Code

    1. <form method="post" action="index.php?page=hosting_bestellen&space=">


    Als aller erstes soll er Space ausgeben ??

    Wie schaff ich das??

    Hier einmal der Code.

    Source Code

    1. <script type="text/javascript">
    2. var selected_space = 0.99;
    3. var selected_db = 0.00;
    4. var selected_mail = 0.00;
    5. var selected_net = 0.00;
    6. var selected_payment = 0;
    7. function recalcPrice(type, element) {
    8. switch(type) {
    9. case "space":
    10. selected_space = calc(element);
    11. break;
    12. case "db":
    13. selected_db = calc(element);
    14. break;
    15. case "mail":
    16. selected_mail = calc(element);
    17. break;
    18. case "net":
    19. selected_net = calc(element);
    20. break;
    21. case "payment":
    22. break;
    23. case "month":
    24. var month = element.options[element.selectedIndex];
    25. selected_month = parseInt(month.value);
    26. break;
    27. }
    28. var global_price = parseFloat(selected_space) + parseFloat(selected_db) + parseFloat(selected_mail) + parseFloat(selected_net);
    29. document.getElementById("summe").innerHTML = global_price.toFixed(2).replace(".", ",") + " €";
    30. }
    31. function calc(element) {
    32. var option = element.options[element.selectedIndex];
    33. var price_temp = option.className;
    34. var price_repl = price_temp.replace(/price_/g, "");
    35. var price = price_repl.replace(/_/g, ".");
    36. return parseFloat(price);
    37. }
    38. </script>
    Display All

    Source Code

    1. <div style="margin-left: 10px;">
    2. <h2
    3. style="border-width: 0px; margin: 0px 0px 12px; padding: 0px; font-size: 22px; vertical-align: baseline; background-color: transparent; color: rgb(127, 127, 127) ! important; line-height: 24px;"><cufon
    4. class="cufon cufon-canvas" alt="Haftung/Urheberrecht"
    5. style="text-indent: 0px ! important; position: relative ! important; vertical-align: middle ! important; font-size: 1px ! important; line-height: 1px ! important; width: 230px; height: 22px;"><cufontext
    6. style="width: 0px ! important; height: 0px ! important; text-indent: -10000in ! important;"></cufontext></cufon>Hosting</h2>
    7. <small>Bitte füllen Sie nun alle Felder aus. Zu jeder Bestellung speichern wir die IP Adresse und Fake Bestellungen werden von uns zur Anzeige gebracht. Alle Felder sind Pflichtfelder!</small><br /><br />
    8. <form method="post" action="index.php?page=hosting_bestellen&space=$_POST['space'];">
    9. <table style="width:50%;">
    10. <tr>
    11. <td>Speicherplatz</td>
    12. <td>&nbsp;</td>
    13. <td>
    14. <select name="space" onchange="recalcPrice('space', this);">
    15. <?php
    16. foreach($space AS $i => $data) {
    17. print "<option value=\"" . $i . "\" class=\"price_" . number_format($data['price'], 2, "_", "") . "\">" . $data['name'] . " [+" . number_format($data['price'], 2, ",", ".") . " €]</option>";
    18. }
    19. ?>
    20. </select>
    21. </td>
    22. </tr>
    23. <tr>
    24. <td>Datenbanken</td>
    25. <td>&nbsp;</td>
    26. <td>
    27. <select name="database" onchange="recalcPrice('db', this);">
    28. <?php
    29. foreach($database AS $i => $data) {
    30. print "<option value=\"" . $i . "\" class=\"price_" . number_format($data['price'], 2, "_", "") . "\">" . $data['name'] . " [+" . number_format($data['price'], 2, ",", ".") . " €]</option>";
    31. }
    32. ?>
    33. </select>
    34. </td>
    35. </tr>
    36. <tr>
    37. <td>E-Mail Adressen</td>
    38. <td>&nbsp;</td>
    39. <td>
    40. <select name="mail" onchange="recalcPrice('mail', this);">
    41. <?php
    42. foreach($mails AS $i => $data) {
    43. print "<option value=\"" . $i . "\" class=\"price_" . number_format($data['price'], 2, "_", "") . "\">" . $data['name'] . " [+" . number_format($data['price'], 2, ",", ".") . " €]</option>";
    44. }
    45. ?>
    46. </select>
    47. </td>
    48. </tr>
    49. <tr>
    50. <td>Traffic</td>
    51. <td>&nbsp;</td>
    52. <td>
    53. <select name="traffic" onchange="recalcPrice('net', this);">
    54. <?php
    55. foreach($traffic AS $i => $data) {
    56. print "<option value=\"" . $i . "\" class=\"price_" . number_format(($data['price'] == null ? 0.00 : $data['price']), 2, "_", "") . "\">" . $data['name'] . ($data['price'] == null ? "" : " [+" . numer_format($data['price'], 2, ",", ".") . " €]") . "</option>";
    57. }
    58. ?>
    59. </select>
    60. </td>
    61. </tr>
    62. <tr>
    63. <td>&nbsp;</td>
    64. <td>Gesamtpreis:</td>
    65. <td style="font-weight: bold;" id="summe">0,99 €</td>
    66. </tr>
    67. <tr>
    68. <td>&nbsp;</td>
    69. <td>&nbsp;</td>
    70. <td>
    71. <input type="submit" name="order" value="Bestellen!" />
    72. </td>
    73. </tr>
    74. </table>
    75. </form>
    76. </div>
    Display All



    Danke schon mal für die Hilfe :)

    Gruß

    // edit by vince - codehighlighting

    The post was edited 4 times, last by jimmy ().

  • Ja genau so müsste er ja die Value ausgeben tut er nicht meine value werden nämlich von der index.php augerufen

    ich hänge Sie mal an

    PHP Source Code

    1. <?php
    2. session_start();
    3. // Daten für die Bestellung!
    4. $domain = array();
    5. $domain[] = array("name" => ".de", "price" => 0.75);
    6. $domain[] = array("name" => ".org", "price" => 0.95);
    7. $domain[] = array("name" => ".net", "price" => 0.85);
    8. $domain[] = array("name" => ".info", "price" => 0.75);
    9. $domain[] = array("name" => ".eu", "price" => 1.10);
    10. $domain[] = array("name" => ".com", "price" => 0.75);
    11. $space = array();
    12. $space[] = array("name" => "256 MB", "price" => 0.99);
    13. $space[] = array("name" => "512 MB", "price" => 1.99);
    14. $space[] = array("name" => "1024 MB", "price" => 2.99);
    15. $space[] = array("name" => "2048 MB", "price" => 3.99);
    16. $database = array();
    17. $database[] = array("name" => "10", "price" => 0.00);
    18. $database[] = array("name" => "20", "price" => 0.99);
    19. $database[] = array("name" => "50", "price" => 1.99);
    20. $mails = array();
    21. $mails[] = array("name" => "25", "price" => 0.00);
    22. $mails[] = array("name" => "30", "price" => 0.49);
    23. $mails[] = array("name" => "50", "price" => 0.99);
    24. $traffic = array();
    25. $traffic[] = array("name" => "unlimited", "price" => null);
    26. $kern = array();
    27. $kern [] = array("name" => "1 Kern (3 GHz)", "price" => 0.00);
    28. $kern [] = array("name" => "2 Kerne (6 Ghz)", "price" => 1.99);
    29. $festplatte = array();
    30. $festplatte[] = array("name" => "Bitte wählen", "price" => null);
    31. $festplatte [] = array("name" => "10 Gbyte", "price" => 1.00);
    32. $festplatte [] = array("name" => "20 Gbyte", "price" => 2.50);
    33. $festplatte [] = array("name" => "30 Gbyte", "price" => 4.00);
    34. $festplatte [] = array("name" => "50 Gbyte", "price" => 5.99);
    35. $arbeitsspeicher = array();
    36. $arbeitsspeicher[] = array("name" => "Bitte wählen", "price" => null);
    37. $arbeitsspeicher [] = array("name" => "512 Mbyte", "price" => 2.49);
    38. $arbeitsspeicher [] = array("name" => "1024 Mbyte", "price" => 3.49);
    39. $arbeitsspeicher [] = array("name" => "2048 Mbyte", "price" => 4.49);
    40. $arbeitsspeicher [] = array("name" => "4096 Mbyte", "price" => 8.98);
    41. $vtraffic = array();
    42. $vtraffic[] = array("name" => "Bitte wählen", "price" => null);
    43. $vtraffic [] = array("name" => "500 Gbyte", "price" => 1.00);
    44. $vtraffic [] = array("name" => "Traffic Flat **", "price" => 2.99);
    45. $betriebssystem = array();
    46. $betriebssystem[] = array("name" => "Bitte wählen", "price" => null);
    47. $betriebssystem [] = array("name" => "Linux *", "price" => 0.49);
    48. $betriebssystem [] = array("name" => "Windows 2008 R2", "price" => 9.99);
    49. $ip = array();
    50. $ip [] = array("name" => "1 IP-Adressen", "price" => 0.00);
    51. $ip [] = array("name" => "2 IP-Adressen", "price" => 0.49);
    52. $ip [] = array("name" => "3 IP-Adressen", "price" => 0.99);
    53. $ip [] = array("name" => "4 IP-Adressen", "price" => 1.49);
    54. $ip [] = array("name" => "5 IP-Adressen", "price" => 1.99);
    55. $vorauszahlung = array();
    56. $vorauszahlung[] = array("name" => "3", "nachlass" => 5);
    57. $vorauszahlung[] = array("name" => "6", "nachlass" => 7.5);
    58. $vorauszahlung[] = array("name" => "12", "nachlass" => 10);
    59. if($_GET['page'] == "") {
    60. header("Location: ?page=home");
    61. }
    62. include("pages/overview.php");
    63. ?>
    Display All
  • Bitte korrigiere das Syntax Highlighting. Die Button findest du unter dem Texteditor. Ansonsten verstehe ich nicht ganz was du ausgeben willst. Hier ein paar Ausgaben zur Auswahl

    Source Code

    1. // Array ( [space] => 3 [database] => 2 [mail] => 2 [traffic] => 0 [order] => Bestellen! )
    2. print_r($_POST);
    3. // Array ( [name] => 256 MB [price] => 0.99 )
    4. print_r($space[$_POST['space']]);
    5. // 256 MB
    6. echo $space[$_POST['space']]['name'];
  • Jan Thurau wrote:

    Du musst bei der entsprechend aktiv gesetzten Option die Eigenschaft "selected" auf selected setzen. Also <option selected="selected">


    So ??

    Source Code

    1. print "<option selected=\'selected' value=\"" . $i . "\" class=\"price_" . number_format($data['price'], 2, "_", "") . "\">" . $data['name'] . " [+" . number_format($data['price'], 2, ",", ".") . " €]</option>";
  • Guten Abend,

    Bin leider nicht Perfekt in PHP

    Können Sie mir das mal binden ??

    PHP Source Code

    1. <td style="text-align: left;">
    2. <select name="space" onchange="recalcPrice('space', this);">
    3. <?php
    4. foreach($space AS $i => $data) {
    5. print "<option value=\"" . $i . "\" class=\"price_" . number_format($data['price'], 2, "_", "") . "\">" . $data['name'] . " [+" . number_format($data['price'], 2, ",", ".") . " €]</option>";
    6. }
    7. ?>
    8. </select>
    9. </td>


    PHP Source Code

    1. <form method="post" action="index.php?page=gameserver_bestellen&space=<?php echo print_r($space[$_POST['space']]);