0

I need to be able to autopopulate a text field with "one-hidden" when a customer checks a checkbox, but so far examples I've found online do not seem to work, or I'm putting them in the wrong place.

$('#flight-include').change(function(){
    $("#one-control").text("");
    if ($('#flight-include').is(':checked')) { 
        $("#one-control").text("one-hidden"); 
    }
});

I put the above in the function file, and it did nothing, so guessing I'm doing something wrong or missing something.

Flight-control is the checkbox, one-control is the text field. "one-hidden" is the text that needs to appear in the text field when the flight-include box is checked.

Can someone help, as I'm pretty clueless with this type of coding. Many thanks

Tried executing the code above in the function file, but possible not the right place.

Jatniel
  • 1,967
  • 2
  • 19
  • 27
  • Your function looks fine, however, the `functions.php` file is for php code. The code you're trying to execute is javascript which needs to be loaded on the client browser and executed once the [document is ready](http://learn.jquery.com/using-jquery-core/document-ready/). I suggest you take an online course in javascript and jquery in order to better understand how to solve this kind of problems. – Aurovrata Jun 02 '23 at 12:01
  • Thank @Aurovrata appreciate the advice and most certainly and learning about various scripting languages. – Tom Kidd Jun 02 '23 at 13:08

0 Answers0