
richarddunnebsc
Members-
Posts
19 -
Joined
-
Last visited
Everything posted by richarddunnebsc
-
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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? -
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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); -
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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? -
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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. -
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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 -
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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? -
Change button text and function name
richarddunnebsc replied to richarddunnebsc's topic in Javascript Help
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. -
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", "-");
-
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?
-
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
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? -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
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. -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
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 -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
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. -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
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 -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
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; -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
I'm not passing any data from Logic.php (Logic class) to Data.php (Data class) There is no dependency on Data.php by Logic.php, but I need to include Data.php in Logic.php in order to call methods in Data.php Data.php requires Config.php in order to access the database. As part of a user email verification, I want to access the necessary method(s) in the Data class from Logic.php. Hope that clarifies. As I have instantiated the Data class and Data.php is included in Logic.php, then shouldn't all the Data class methods by accessible to the Logic class using $this->FunctionName? If not, how else do I call methods in the Data class from Logic? -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
I want to call the Data class method Email() in Data.php from Logic.php -
Call to undefined method in included file
richarddunnebsc replied to richarddunnebsc's topic in PHP Coding Help
Using require instead of include makes no difference. If I use this instead $registered = $data->Email(); I get Undefined variable: data. If by parens you mean parenthesis, if I leave them out, I get failed to open stream, no such file Dataphp. -
I'm using wamp. I have Logic.php and Data.php in the same folder. In Logic.php I have include_once('Data.php'); and a Logic class containing public function EmailVerify() { try { $registered = $this->Email(); if($registered) { echo "Registered"; } } catch (PDOException $e) { echo 'Error: ' . $e->getMessage(); } } I am getting call to undefined function Logic::Email(), Email() is a method in Data.php What am I doing wrong?