Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
Pass javaScript variable to php or workaround for just php

I'm trying to get a JavaScript variable to php without refreshing the page or submitting the form. I think my problem is that php is on the server side. I have a button that's set in a php echo...

<input type='button' value='Edit' name='editbtn' onmouseup='reply_click(this.id)' onclick='edit()' id = '" . $row['id'] . "'

This button works correctly. I didn't provide all the code surrounding it, just the part in question. I can inspect the button element in the browser and the "id" shows the correct id number.

Next I'm using some test JavaScript in an effort to get the id to php with having to refresh the page or submit the form.

echo "<script type='text/javascript'>
        function reply_click(clicked_id){
            var selid = clicked_id;
            alert(selid);
            document.writeln(selid);        
        } </script>";

This code works. I get the correct id to show in an alert or document.writeln. The problem comes when I try to set this to a php variable like this...

$testid = "<script type='text/javascript'>document.writeln(selid);</script>";
echo $testid;

$testid returns nothing.

Is there a way to do this or is there a workaround using only php? I need to do this without submitting the form or refreshing the page. Is that possible? The end goal is to create another MySQL statement using that id value. For example: SELECT * FROM table WHERE id = the $testid from JavaScript.

Thank you!

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!