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

189
Views
Jquery inside a php file to replace a form value with a URL Parameter

so I have a a PHP Form handler that I have a hidden field in. I use this all the time in my header, however, I have not used it inside a php file. I access the jquery library, use $(document).ready(function () and have my variables inside, as well as getURLParameter("tid"), then ($tbody).html $("tbody").html($("tbody").html().replace(/{{transaction_id}}/g,replaceString));

I keep getting the error: Uncaught ReferenceError: getURLParameter is not defined

I'm probably missing something here, as I have not done this inside a PHP file before.

Should I use .php instead of .html?

Here is the snippet of code:

<?php } ?>
    <table width="250"><tbody>
        <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
$(document).ready(function () {
    var replaceString = "NO TID";
    var urlTerm = getURLParameter("tid");
    if (urlTerm.trim().length > 0 && urlTerm != "null") {
        replaceString = decodeURIComponent(urlTerm).replace(/\+/g,' ');
    }
    $("input.transaction_id").html($("input.transaction_id").html().replace(/\{\{transaction_id\}\}/g,replaceString));
});
</script>
<tr><td><form id="signupform" class="signup_form" action="/testing-kirby.php" method="post"><div><div><input  class="signup-name-area" style="height: 32px; width: 325px;" name="name" type="text" placeholder="Full Name"><br><br><input class="signup-email-area" style="height: 32px; width: 325px;" name="email" required="required" type="email" placeholder="email@example.com"><div style=" margin-top: 15px;"<center><input class="signup-button-2" style="background-color: red; height: 48px;" type="submit" value="Sign Petition"></center></div><input name="loc" type="hidden" value="header"></div></div><input name="tid" class="transaction_id" type="hidden" value="{{transaction_id}}"></div></form><p style="text-align: center;">Sponsored by:</p><p style="text-align:center;"><img src="https://wolfdaily.com/wp-content/uploads/2020/05/Wolf-Daily-Final-160h.png" width="200"></p></td></tr></tbody></table>

Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't need to replace it with jQuery. If its php you can get the url parameter like

var urlTerm = "<?php echo $_GET["tid"] ?>";

However if you still wana do it with JavaScript consider the solution here because you need to define the function getURLParameter somewhere in your code or you forgot to import it.

about 4 years ago · Juan Pablo Isaza Report
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!