2

I have been trying to set the input values on a public DHL form in all the different ways the internet suggests, but it does not work.
I've tried the many Stack Overflow answers on this topic, but this form is just special.

The DHL form

The classic way to set the value of the "first and last name" field:

// using firefox browser developer console:
var input = document.getElementById('address.receiver.name2');
input.value = 'John'; // has a temporary effect
// or
input.setAttribute('value', 'John'); // doesn't work

Setting input.value = 'John'; shows the value inside the input field. But any clicking inside and around the form or submitting the form, removes the value again.

Only the value that is manually typed in by hand, is preserved in the form.

I see that there is multiple events on the input field. I failed to either disable or trigger them. Also, the contents of the form are saved. Navigating and refreshing keeps the content. Seems to be a lot of magic going on.

I want to set the values of the input fields.

8
  • 1
    You have to fire a change event on that input Commented Sep 15, 2023 at 16:41
  • stackoverflow.com/questions/136617/… Commented Sep 15, 2023 at 16:42
  • But any clicking inside and around the form ...removes the value again; sounds like there is another event firing on the form itself. You'll need to investigate that. Commented Sep 15, 2023 at 16:43
  • 2
    Try the deprecated document.execCommand, example. Commented Sep 15, 2023 at 18:04
  • 1
    @chrwahl op doesn't have a problem with a default form, but a specific one Commented Sep 18, 2023 at 8:33

1 Answer 1

1

Try the deprecated document.execCommand, example. – wOxxOm

This idea from wOxxOm worked.

Here is a working solution using document.executeCommand on the form:

// using firefox browser developer console:
var input = document.getElementById('address.receiver.name2'); // get the input field by id
input.focus(); // sets this input as the current one to manipulate
document.execCommand('selectAll', false, null); // selects all content in the input field (so if there is something there already it gets overriden)
document.execCommand('insertText', false, 'John'); // sets the field to string John
input.blur(); // removes focus
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.