2

This is my question:

I got an jsp page, this jsp has many text fields like this:

<html:text property="cicPF" maxlength="9" style="text-transform: uppercase;" onfocus="disableIfeFields()"/>

So I want to disable some of this text fields when the focus it's in a specific field

But no one of this fields has "id" label, and I can't modify it to include it.

May I disable the fields usig their given names, no one of this repeats the same name.

for example with a function like this:

function disableIfeFields(){
    document.getElementsByName("numIdentificacionPF").disabled = true;

}

thanks

1

3 Answers 3

2

You need to loop through the list and disable all the fields you want that way, used input to show example:

function disableIfeFields() {
  document.getElementsByName("numIdentificacionPF").forEach((e) => {
    e.disabled = true;
  });
}
<html:text property="cicPF" maxlength="9" style="text-transform: uppercase;" />
<input onfocus="disableIfeFields()" type="text" name="fname">
<input type="text" name="numIdentificacionPF">
<input type="text" name="numIdentificacionPF">
<input type="text" name="numIdentificacionPF">
<input type="text" name="numIdentificacionPF">
<input type="text" name="numIdentificacionPF">

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

Comments

2

Maybe like this:

function disableIfeFields(){
    document.querySelectorAll('[property="cicPF"]')[0].disabled = true;
}

disableIfeFields();
<input type="text" property="cicPF" maxlength="9" style="text-transform: uppercase;" onfocus="disableIfeFields()"/>

Comments

2

Hopefully the following should help. Because the selection result is a list of elements you will have to loop through the results. Please note that since you said no input repeats the same name, I'm using querySelectorAll, which might be a more suitable method after all…

var inputs = document.querySelectorAll('input[type="text"]');
for (var i = 0; i < inputs.length; i++) {
    if (inputs[i].id === 'label') {
        continue;
    }
    inputs[i].disabled = true;
}

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.