Remplir un champ de formulaire avc du texte contenant un retour-ligne

J’essaie la fonction do JavaScript pour remplir un champ de formulaire. Ça marche s’il n’y a pas de retour à la ligne dans le texte, mais dès que je crée une chaîne de caractères avec ‘return’ ou ‘linefeed’ ou ‘\n’ ça ne marche plus? Une idée?

This is what I got as an English translation for your question. I hope it’s close enough. I’m afraid that you’ll have to get my post translated some way or another.

I’m trying the JavaScript function to fill in a form field. It works if there is no line feed in the text, but as soon as I create a string with ‘return’ or ‘linefeed’ or ‘\n’ it doesn’t work anymore

I don’t think that a form input field will necessarily be able to accept linefeeds. Some will filter them out. You don’t provide the page/form/field in question so I can’t test it.

But here is something I would try first. To insert a ‘linefeed’, type control-option-j. For ‘return’, type control-option-m. You can try these key combinations out in textedit to confirm that they work in a general environment. I don’t typically want to enter linefeeds in an input field but sometimes I want to enter a tab (control-option-i) and this usally works.

I don’t think any settings require changing for them to work but I’ve forgotten where I learned of them. Hope this helps.

1 Like

This is a textarea that I’m trying to fill.

But as soon as I insert a return statement, it stops working:

set myData to "Line 1 " & return & “Line 2”
or
set myData to "Line 1 & linefeed & “Line 2”
or
set myData to “Line 1
Line 2”
or
set myData to “Line 1 ¬
Line 2”

whereas

set myData to “Line 1 - Line 2” works.
set cmd to “document.forms[0].elements[‘texte’].value='” & myData & “'”
do JavaScript cmd

I’m not very proficient in English or French, so I may be misunderstanding the intended meaning.
But please try the following approach:

Je ne maîtrise pas très bien l’anglais ni le français, donc il est possible que je comprenne mal votre intention.
Mais veuillez essayer la méthode suivante :slight_smile:

<textarea id="my_textarea" ></textarea>

tell application "Safari"
	do JavaScript "document.getElementById('my_textarea').value='Line1\\u000ALine2';" in front document
end tell

It might simply be that it hasn’t been escaped.

Il est possible que ce soit simplement un problème d’absence d’échappement.

tell application "Safari"
	do JavaScript "document.getElementById('my_textarea').value='AA\\nBB';" in front document
end tell

This is something very good that I’ve learned.

1 Like

It’s works fine. I have about fifteen textareas in my form, and the data comes from FileMaker. This will save me a lot of time. Thank you so much! Have a nice day.

1 Like