Sinisterly
PHP noob question - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: PHP (https://sinister.li/Forum-PHP)
+--- Thread: PHP noob question (/Thread-PHP-noob-question)



PHP noob question - Vi-Sion - 03-31-2017

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


RE: PHP noob question - Skryptec - 04-05-2017

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";


RE: PHP noob question - Vi-Sion - 04-05-2017

Couldn't understand what your post meant sorry.


RE: PHP noob question - Pikami - 04-05-2017

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?


RE: PHP noob question - Vi-Sion - 04-05-2017

(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>