This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Javascript

By: a guest on Nov 27th, 2012  |  syntax: None  |  size: 4.23 KB  |  views: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.         $funds       =    $_POST['prcbox'];
  4.         $ageval       =   $_POST['age'];
  5.  
  6.         echo "You have $funds to spend!";
  7.  
  8. ?>
  9.  
  10. <input type="hidden" id="age" name="age" value="$ageval">
  11.  
  12.  
  13. <?php
  14.  
  15. fgetcsv_PHP();
  16.  
  17. function fgetcsv_PHP()
  18. {
  19.     /*
  20.      * See if we can open a file named fgetcsv.csv in
  21.      * read mode, if we can then assign pointer to this
  22.      * file to a variable named $handle
  23.      * 'r' - Open for reading only; place the file
  24.      *  pointer at the beginning of the file.
  25.      */
  26.     if (($handle = fopen("./assets/actors.csv", "r")) !== FALSE)
  27.     {
  28.         /*
  29.          * fgetcsv( resource $handle  int $length  string $delimiter )
  30.          *
  31.          * resource $handle
  32.          * A valid file pointer to a file successfully opened by fopen(),
  33.          * popen(), or fsockopen().
  34.          *
  35.          * int $length
  36.          * Must be greater than the longest line (in characters) to be
  37.          * found in the CSV file (allowing for trailing line-end characters).
  38.          * It became optional in PHP 5. Omitting this parameter (or setting
  39.          * it to 0 in PHP 5.0.4 and later) the maximum line length is not
  40.          * limited, which is slightly slower.
  41.          *
  42.          * string $delimiter
  43.          * Set the field delimiter (one character only).
  44.          *
  45.          * RETURN VALUES
  46.          *
  47.          * Returns an indexed array containing the fields read.
  48.          *
  49.          * Note: A blank line in a CSV file will be returned as an array
  50.          *       comprising a single null field, and will not be treated
  51.          *       as an error.
  52.          *
  53.          * Note: If PHP is not properly recognizing the line endings when
  54.          *       reading files either on or created by a Macintosh computer,
  55.          *       enabling the auto_detect_line_endings run-time configuration
  56.          *       option may help resolve the problem.
  57.          *
  58.          * fgetcsv() returns NULL if an invalid handle is supplied or FALSE
  59.          * on other errors, and when the end of file has been reached.
  60.          */
  61.  
  62.  
  63.         $length = 1000;
  64.         $delimiter = ",";
  65.  
  66.         /*
  67.          * Print the opening table tag to begin buiding HTML table
  68.          * and the first row of the table; with column names
  69.          */
  70.         echo "<table>\n";
  71.         echo "<td>&nbsp;</td><td width='90px'><b>Name</b></td><td><b>Surname</b></td>";
  72.  
  73.         /*
  74.          * Loop through the array of values returned by fgetcsv until there are
  75.          * no more lines (indicated by FALSE)
  76.          */
  77.         while ( ( $data = fgetcsv( $handle, $length, $delimiter ) ) !== FALSE )
  78.         {
  79.             // Count number of array elements in $data
  80.             $num = count($data);
  81.             // Print opening table row HTML tag
  82.             echo "<tr>\n";
  83.             echo "<td width='90px'><button onclick='myApproach();'>Approach</button></td>\n";
  84.  
  85.             /*
  86.              * Loop through the $data array and output each element
  87.              * wrapped by opening and closing table data HTML tags
  88.              */
  89.             for ($c=0; $c < $num; $c++)
  90.             {
  91.                 echo "<td>".$data[$c]."</td>\n";
  92.             }
  93.            
  94.             echo "<td width='90px'><textarea id='agebox' style='width:70px;' readonly='readonly' onchange='submitChange()'></textarea></td>\n";
  95.            
  96.             echo "<td width='90px'><input type='submit' id='submit' style='display: none;' /></td>\n";
  97.  
  98.  
  99.            
  100.            
  101.  
  102.             // Print closing table row HTML tag
  103.             echo "</tr>\n";
  104.         }
  105.  
  106.         // Print close table HTML tag
  107.         echo "</table>";
  108.  
  109.         // Close the file pointed to by $handle
  110.         fclose($handle);
  111.     }
  112. }
  113.  
  114. ?>
  115.  
  116. <script>
  117. function myApproach() {
  118.   var age,voteable;
  119.   age=document.getElementById("age").value;
  120.   voteable=(age<18)?"Too young":"Old enough";
  121.   document.getElementById("agebox").value=voteable;
  122. }
  123.  
  124. function submitChange()
  125. {
  126.  var inputOne = document.getElementById("agebox");
  127.  var inputSubmit = document.getElementById("submit");
  128.      if(inputOne.value == "Old enough")
  129.      {
  130.           inputSubmit.style.display = "block";
  131.      }
  132.      else
  133.      {
  134.           inputSubmit.style.display = "none";
  135.      }
  136. }
  137.  
  138. </script>
clone this paste RAW Paste Data