0

enter image description here

How do I transform these .getElementIds and the last line into PHP code? I've been struggling mightily on how to tackle these.

  • If you're looking for the values, you need to send them through a form, use the name attribute on the elements. – Da Mahdi03 Mar 21 '21 at 06:45
  • Correct @DaMahdi03 - In the case he wants the values, he needs to make a form and then POST or GET all the values. – Marcellin Wabo Mar 21 '21 at 06:55
  • This answer should assist you... https://stackoverflow.com/a/1917626/1533592 – dale landry Mar 21 '21 at 07:22
  • 1
    Does this answer your question? [How do I pass JavaScript variables to PHP?](https://stackoverflow.com/questions/1917576/how-do-i-pass-javascript-variables-to-php) – dale landry Mar 21 '21 at 07:23

2 Answers2

0

I am not sure if this solves your issue, but if you're trying to use a javascript code inside a .php file, you can just echo the js code. e.g.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="first-name-field">
  Howdy
  </div>
</body>
</html>

<?php

echo "
            <script type=\"text/javascript\">
            var e = document.getElementById('first-name-field')
            console.log(e);
            </script>";
?>

Hope this solves your issue

0

I don't understand but if you mean to send your attr to PHP/server then do something like (Post data to server).

$.post("hello.php", {
    firstName: firstName,
    city:city,
    zip:zip
  }, function(result){
    alert(result);
  });
});

hello.php is a file sitting on the server to serve your request, bellow is a code in hello.php

<?php echo $_POST['city']; ?>
James in code
  • 73
  • 1
  • 6