shahriar Posted April 30, 2020 Share Posted April 30, 2020 translate my code please; javascript to php. very very thanks. <!DOCTYPE html> <html> <body> <form> <input type="checkbox" name="myfilter" value=",photo">With tag1<br> <input type="checkbox" name="myfilter" value=",pic">With tag2<br> <input type="checkbox" name="myfilter" value=",cream">With tag3<br> <input id="year1" value=""> <input id="month1" value=""> <input id="day1" value=""> <br> <input id="search1" value=""> <br> </form> <button onclick="myFunction()">Search It!</button> <p id="demo"></p> <script> function myFunction() { var myfilter = document.forms[0]; var txt = ""; var i; for (i = 0; i < myfilter.length; i++) { if (myfilter[i].checked) { txt = txt + myfilter[i].value; } var year = "&year=" + document.getElementById("year1").value; var month = "&month=" + document.getElementById("month1").value; var day = "&day=" + document.getElementById("day1").value; var search = "&s=" + document.getElementById("search1").value; } var zzz = "http://test.com/class/category-photography/?tag=" + txt + year + month + day + search; window.location.assign(zzz) } </script> </body> </html> Link to comment Share on other sites More sharing options...
dsonesuk Posted April 30, 2020 Share Posted April 30, 2020 (edited) You can't! php produces the html, while javascript manipulates that html code depending on events after that html code is produced. Edited April 30, 2020 by dsonesuk Link to comment Share on other sites More sharing options...
shahriar Posted April 30, 2020 Author Share Posted April 30, 2020 why not? Link to comment Share on other sites More sharing options...
shahriar Posted April 30, 2020 Author Share Posted April 30, 2020 (edited) it` simple. var x = 0 --> $x = 0 But i am amateur. Edited April 30, 2020 by shahriar Link to comment Share on other sites More sharing options...
dsonesuk Posted April 30, 2020 Share Posted April 30, 2020 OK! Do the same with onclick that runs the function in php, or window.location in php, and we'll see how far you get, go on. It's simple so you should be able to do those two simple things. Link to comment Share on other sites More sharing options...
Ingolme Posted April 30, 2020 Share Posted April 30, 2020 While it's usually not possible to translate Javascript to PHP, in this particular case the same result can be achieved using PHP. You an replace the onclick with a form submission and window.location can be replaced with an HTTP location header. Link to comment Share on other sites More sharing options...
Ingolme Posted April 30, 2020 Share Posted April 30, 2020 You should go through the effort of learning PHP rather than asking people to write code for you. Most of us have jobs and can't spend the time writing code if we're not getting paid for it, but just to illustrate my previous post, I'll write the code for this example. <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $data = [ 'tag' => implode(',', $_POST['txt']), 'year' => $_POST['year'], 'month' => $_POST['month'], 'day' => $_POST['day'], 's' => $_POST['s'] ]; $target = 'http://test.com/class/category-photography/?' . http_build_query($data); header("Location: {$target}"); exit; } ?> <!DOCTYPE html> <html> <body> <form method="POST"> <input type="checkbox" name="txt[]" value="photo">With tag1<br> <input type="checkbox" name="txt[]" value="pic">With tag2<br> <input type="checkbox" name="txt[]" value="cream">With tag3<br> <input name="year" value=""> <input name="month" value=""> <input name="day" value=""> <br> <input name="s" value=""> <br> <button type="submit">Search It!</button> </form> </body> </html> 1 Link to comment Share on other sites More sharing options...
shahriar Posted May 1, 2020 Author Share Posted May 1, 2020 7 hours ago, Ingolme said: You should go through the effort of learning PHP rather than asking people to write code for you. Most of us have jobs and can't spend the time writing code if we're not getting paid for it, but just to illustrate my previous post, I'll write the code for this example. <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $data = [ 'tag' => implode(',', $_POST['txt']), 'year' => $_POST['year'], 'month' => $_POST['month'], 'day' => $_POST['day'], 's' => $_POST['s'] ]; $target = 'http://test.com/class/category-photography/?' . http_build_query($data); header("Location: {$target}"); exit; } ?> <!DOCTYPE html> <html> <body> <form method="POST"> <input type="checkbox" name="txt[]" value="photo">With tag1<br> <input type="checkbox" name="txt[]" value="pic">With tag2<br> <input type="checkbox" name="txt[]" value="cream">With tag3<br> <input name="year" value=""> <input name="month" value=""> <input name="day" value=""> <br> <input name="s" value=""> <br> <button type="submit">Search It!</button> </form> </body> </html> very thanks buddy. very thanks. I know you have job. I only asked for help if anyone was interested and could help. You have been very kind to me Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now