HTML form input tag name element array with JavaScript

前端 未结 5 1774
终归单人心
终归单人心 2020-11-30 03:20

This is a two part question. Someone answered a similar question the other day (which also contained info about this type of array in PHP), but I cannot find it.

1.

5条回答
  •  遥遥无期
    2020-11-30 03:51

    Here’s some PHP and JavaScript demonstration code that shows a simple way to create indexed fields on a form (fields that have the same name) and then process them in both JavaScript and PHP. The fields must have both "ID" names and "NAME" names. Javascript uses the ID and PHP uses the NAME.

    ";
    echo "";
    ?>
    
    ";
    echo "";
    $DQ = '"';  # Constant for building string with double quotes in it.
    
    if (isset($_POST["MyButton"])) {
      $TheNameArray = $_POST["TheName"];  # Use NAME in PHP
      echo "

    Here are the names you submitted to server:

    "; for ($i = 0; $i <3; $i++) { echo $TheNameArray[$i] . "
    "; } } echo "

    Enter names and submit to server or Javascript

    "; echo "
    "; echo ""; echo ""; echo ""; echo ""; echo "

    "; echo "

    "; echo "
    "; echo ""; echo "";

提交回复
热议问题