Jump to content

richarddunnebsc

Members
  • Posts

    19
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

richarddunnebsc's Achievements

Member

Member (2/5)

0

Reputation

  1. Each new row has a delete button, so each delete button needs an event listener. The way I'm doing it, I only need to add an event listener once, to the second row, because I with each subsequent row added, its just a copy and paste of that row second row. At the moment, the event listener is not being added to the delete button. var ele3 = document.createElement("input"); ele3.type = "button"; ele3.value = "-"; ele3.style.width = "100%"; ele3.addEventListener('click', function(e){DeleteRow();}); Can event listeners be added to elements this way?
  2. I did look at the example, I just decided to go with a different design. My problem at the moment is the event listener is not being added to the delete row button var cell3 = document.createElement("td"); cell3.style.width = "5%"; var ele3 = document.createElement("input"); ele3.type = "button"; ele3.value = "-"; ele3.style.width = "100%"; ele3.addEventListener('click', function() {DeleteRow}); cell3.appendChild(ele3); row.appendChild(cell3); table.appendChild(row);
  3. After some reflection I have changed the design to hopefully simplify. The table must have at least one input row . Instead of using one table I am using 3. Table 1 contains a header row and row 1 which is required. If the user needs/wants to add one or more additional rows, those rows are in a separate table. The third table contains the addRow button. To add a row, if the 2nd table is empty, add a row dynamically. If not empty, clone the last row and append at the end. In adding a row dynamically, when adding an event listener to an input button, does a parameter have/need to be added separately? If so, how do I do that?
  4. I also tried using getElementsByName var row = document.getElementsByName('Buttons').length-2; document.getElementsByName("Buttons")[row].setAttribute("value","-"); document.getElementsByName("Buttons")[row].removeEventListener("click",AddRow); It isn't removing the event listener.
  5. I got the clone working var x=document.getElementById("tableName"); var node=x.rows[1].cloneNode(true); x.appendChild(node); What I want to do next is replace an input event listener using removeEventListener then addEventListener. This is what I have var row = document.getElementById('tableName').length-1; document.getElementById('tablename')[row].removeEventListener("click",AddRow); Its not working needless to say
  6. I have decided to try cloning. var table = $("#tableName"); var second = $('#tableName tr').eq(2); var clone = second.cloneNode(true); alert(); JavaScript doesn't seems to like cloneNode(), the alert is not executing. Basically I need to copy the second row of the table and append it to the end. I can then replace the input function and value of the button. Any ideas/suggestions?
  7. I figured out how to change the button value using setAttribute. While adding another function is one way to go about about, I'd rather just add a parameter to the existing function.
  8. I have a table, 1 row with 4 cells. Cell 0 input type button, value "+", class="buttons", with onclick="AddRow()", Cell 1 input type text, Cells 2 & 3 inputs type number On click I want to add a new row, then change the button function on the preceding row from AddRow to DeleteRow, and change the value of that button from + to - I have added a new row, its the other parts I'm struggling to figure out. Any guidance appreciated. This is what I have at the moment var rowsCount = $('.buttons').length-2; document.getElementsByClassName('buttons')[rowsCount].prop("value", "-");
  9. The Database connection class Db (Config.php) class Db extends PDO { private $host = "localhost"; private $user = "root"; private $pass = ""; private $dbName = "Users"; private $charset = "utf8mb4"; public function __construct() { $dsn = "mysql:host={$this->host};dbName={$this->dbName};charset={$this->charset}"; parent::__construct($dsn, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } } When I try to do an insert in my Data class (Data.php) try { $pdo = new Db(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $email = filter_var($_POST["Email"],FILTER_VALIDATE_EMAIL); } $sql = "Insert into Users (Email,Name) values(:Email,:Name)"; $stmt= $pdo->prepare($sql); $stmt->execute(array( ':Email' => $_POST["Email"],':Name' => $_POST["Name"] )); if($stmt) { return true; } } catch (PDOException $e) { die('Error: '.$e->getMessage()); } I get this error No Database selected. If I do an isset() on $pdo are creating the object variable it returns true, which would indicate a connection was successful. What am I missing here?
  10. Why is data undefined after $data = new Data; try { if(isset($data)) { $registered = $data->MethodName(); } else { echo "failed"; } } catch (PDOException $e) { echo 'Error: ' . $e->getMessage(); } This reason data is undefined is it's not creating a new Data class object It prints failed. Why is it not creating a new Data class object?
  11. The database connection has been sorted. My only other problem is calling a Data method from my Logic class. I have included Data.php in Logic.php Created a Data class object in Logic.php $data = new Data; then when I call a method in the Data class $registered = $data->MethodName(); I get Undefined variable: data I did the same thing calling a Logic class method from a webpage and had no issue.
  12. This is my Db class in Config.php class Db extends PDO { private $host; private $dbName; private $user; private $pass; private $charset; public function Connect() { $this->host = "localhost"; $this->user = "root"; $this->pass = ""; $this->dbName = "dbName"; $this->charset = "utf8mb4"; try { $dsn = "mysql:host=".$this->host.";dbName=".$this->dbName.";charset=".$this->charset; $pdo = new PDO($dsn, $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); return $pdo; } catch (PDOException $e) { echo 'Error: '.$e->getMessage(); } } } This is the PDO construct in my Data class in Data.php public function __construct() { $pdo = new PDO($this->dsn,$user,$pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } This line is giving Notice: Undefined property: Data::$dsn Notice: Undefined variable: user Notice: Undefined variable: pass Fatal error: Uncaught PDOException: invalid data source name
  13. That's what it says, but as you can see, I have EmailVerify($data) and not EmailVerify() I was interpreting/reading the error message wrong. EmailVerify($data) has an argument in it, but it doesn't receive the argument from the calling method, hence 0 passed. I need to instantiate the Data class in the webpage, then pass it as an argument to the method in the Logic class, that makes sense, I hope. I have echo "yes"; in the Email() method in the Data class. It printed yes.
  14. I only only added the instantiation before my last post, it wasn't there before, as you observed. This code require_once('Data.php'); error_reporting(E_ALL); ini_set('display_errors', '1'); $data = new Data; class Logic { public function EmailVerify($data) { try { $registered = $data->Email(); } catch (PDOException $e) { echo 'Error: ' . $e->getMessage(); } } } $logic = new Logic; gives me Fatal error: Uncaught ArgumentCountError: Too few arguments to function Logic::EmailVerify(), 0 passed in
  15. I instantiated Data in both Data.php and Logic.php, but I still get Undefined variable: data in Logic require_once('Data.php'); error_reporting(E_ALL); ini_set('display_errors', '1'); $data = new Data; class Logic { public function EmailVerify() { try { $registered = $data->Email(); } catch (PDOException $e) { echo 'Error: ' . $e->getMessage(); } } } $logic = new Logic;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.