0

I use these codes to change the value of a field. Only the first two lines run, I tried the rest of the code but it did not work and sometimes the message "Uncaught ReferenceError: $ is not defined" is displayed on the console.

Error displayed on console

document.getElementsByName('tmcp_textfield_6').value = Pak;
document.getElementById("tmcp_textfield_116202d52cbd078").value = Pak;
$("input[name='tmcp_textfield_6']").val(Pak);
document.getElementsByName("tmcp_textfield_6").value = 100;
document.getElementByname("tmcp_textfield_6").value = "100";
$("input[name='tmcp_textfield_6']").val(Pak); 
4
  • Have you imported jquery into the page? Commented Feb 8, 2022 at 21:03
  • 1
    Does this answer your question? JavaScript runtime error: '$' is undefined Commented Feb 8, 2022 at 21:04
  • WordPress uses jQuery instead of $ Commented Feb 8, 2022 at 21:10
  • What have you tried to resolve the problem? Where are you stuck? Commented Feb 14, 2022 at 9:18

1 Answer 1

-1

Find the Working Script here, I think you should switch quotes, where double quotes use single, and where single quotes, use double.

var Pak = "Test"
$('input[name="tmcp_textfield_6"]').val(Pak)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="tmcp_textfield_6">

Be sure you've also included the jquery file to whatever page you need it to work on

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.