Login Register






PHP noob question filter_list
Author
Message
PHP noob question #1
Sry for the question guys but you don't learn unless you dare to ask those questions .
my problem is using document.getElementById in php .
First of all i wanna ask if it could be used in php.
now i'll share what i'm trying to do :

Code:
<!DOCTYPE html> <html> <body> <form action="test2.php" method="post"> First name:<br> <input type="text" name="firstname" value="Mickey"> <br> Last name:<br> <input type="text" id="1" name="lastname" value="Mouse"> <br><br> <input type="submit" value="Submit"> </form> <?php if($_SERVER["REQUEST_METHOD"]=="POST"){ if ($_POST["firstname"] == $_POST["lastname"]) { document.getElementById("1").value="3"; echo "hi"; }} ?> <p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p> </body> </html>

what i'm trying to do is if after submit of the form the first name and last name are the same change the lastname value to 3.
i'm having the following error :

Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\test\test2.php on line 20

line 20 is the line where i used document.getElementById


Everyone should learn how to code, it teaches you how to think.

You don't have to be a Genius to know how to code you just need to be determined.

The computer is incredibly fast, accurate, and stupid; man is unbelievably slow, inaccurate, and brilliant; together they are powerful beyond imagination.

Reply

RE: PHP noob question #2
Code:
<!DOCTYPE html> <html> <body> <form action="test2.php" method="post"> First name:<br> <input type="text" name="firstname" value="Mickey"> <br> Last name:<br> <input type="text" id="1" name="lastname" value="Mouse"> <br><br> <input type="submit" value="Submit"> </form> <?php if($_SERVER["REQUEST_METHOD"]=="POST"){ if ($_POST["firstname"] == $_POST["lastname"]) { document.getElementById("1").value=="3"; echo "hi"; }} ?> <p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p> </body> </html>

.value="3"; -> .value=="3";
[Image: oAqtc2l.png]

Reply

RE: PHP noob question #3
Couldn't understand what your post meant sorry.


Everyone should learn how to code, it teaches you how to think.

You don't have to be a Genius to know how to code you just need to be determined.

The computer is incredibly fast, accurate, and stupid; man is unbelievably slow, inaccurate, and brilliant; together they are powerful beyond imagination.

Reply

RE: PHP noob question #4
You can't do "document.getElementById("1").value="3";" in php because it's html code and it runs on the client side, while php is processed on the server side.
What are you trying to accomplish?

Reply

RE: PHP noob question #5
(04-05-2017, 12:56 PM)Pikami Wrote: You can't do "document.getElementById("1").value="3";" in php because it's html code and it runs on the client side, while php is processed on the server side.
What are you trying to accomplish?

this thread was posted 5 days ago i've already found how it's supposed to be done,thanks for your reply.

Spoiler:
Code:
<!DOCTYPE html> <html> <body> <form action="test2.php" method="post"> First name:<br> <input type="text" name="firstname" value="Mickey"> <br> Last name:<br> <input type="text" id="1" name="lastname" value="Mouse"> <br><br> <input type="submit" value="Submit"> </form> </body> <?php if($_SERVER["REQUEST_METHOD"]=="POST"){ if ($_POST["firstname"] == $_POST["lastname"]) {?> <script>document.getElementById("1").value="3";</script> <?php }} ?> </body> </html>


Everyone should learn how to code, it teaches you how to think.

You don't have to be a Genius to know how to code you just need to be determined.

The computer is incredibly fast, accurate, and stupid; man is unbelievably slow, inaccurate, and brilliant; together they are powerful beyond imagination.

Reply