-1

I have a function that validates an input field if a checkbox is checked:

jQuery("input[type='checkbox'][value='Internet Search']").click(function(){
    if (jQuery("input[type='checkbox'][value='Internet Search']").prop('checked'))
    {
        validatetext("input[name='internetSearch']", 4, 12, "input[type='checkbox'][value='Internet Search']");
    } else {
    errors[12] = true;
        checkInput("input[name='internetSearch']",errors[12]);
    }
});

What I'd like to do is add a read only attribute to the if/else statement. How would this be written?

6
  • Can you provide more details on what you mean by "read only attribute"? Perhaps provide an example? Mar 6, 2016 at 17:59
  • 1
    Umm, did I miss something? How is this related to wordpress?
    – thebigtine
    Mar 6, 2016 at 18:05
  • @VitorArgos sure, if your creating an input field in a form you can add attribute="read only". That will make it so the field is visible, but you can't add text to it. So in the function above I'm say, if the check box "internet search" is checked make the text input field Internet search a required field. What I want to do is make the text field read only until the check box is clicked. Mar 6, 2016 at 19:54
  • @YobdDigital I'm using contact form 7 to create the form, and am creating an additional JS file for my conditional checkbox functions. Mar 6, 2016 at 19:56
  • Even if this is a contact 7 question it's still off topic because that is not directly related to WordPress, but it's a javascript question so technically it belongs on stackoverflow. Just trying to save you running the risk of getting a question closed in the future
    – thebigtine
    Mar 6, 2016 at 20:06

1 Answer 1

0

It`s not completely clear to me how your fields are organized but adding the following piece of code to your if statements should help making the desired input "readonly":

jQuery('input[name="internetSearch"]').prop('readonly', true);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.