Data into textfield

Hello all
how to write this in ESP32 Arduino software?

client.println("<textarea font-size: 40px'; placeholder= 'data' ");

but how to change 'data' in variable

in lua it go like this
client.println("<textarea font-size: 40px'; placeholder= ..var,, ");

SVP help!!

Hello @noelned I think what you're asking is the command for printing in the serial monitor. I know it is serial.print() and for the last serial print you do serial.println() and put you're text or variable in the parantheses

Welcome to the forum

Your topic has been moved to the Programming category

As to your question, personally I would use the sprintf() function to format the output string. This allows you to format a string and include the value of variables

Here is a simple example

    char buffer[100];                                                //the output buffer
    int data = 123;                                                  //some example data
    sprintf(buffer, "The value of the data variable is  %d", data);  //build the output string
    client.print(buffer);                                            //output the string

@zm476 I think that you have misunderstood the question

no not serial but webpage

you are right do you know how to do it in the esp32 software?

do you mean this?
client.println("<textarea font-size: 40px'; placeholder= buffer ");

What I posted will work for an ESP32

No

Read up on how to do formatting with the C function printf() on which sprintf() is based

Basically the printf() function allows you to define the text to be put in the buffer and to include placeholders where the value of variables is to be inserted. In my simple example the %d in the sprintf() text will be replaced with the value of the data variable. As you will discover when you do some research the placeholder must match the type of data to be inserted

Take a look at https://cplusplus.com/reference/cstdio/printf/ for examples

You also need to deal with some special characters. For instance, how do you get double quotation marks into the string when normally they would signal the end of the string ?

The easiest way to try things out is to print the output to the Serial monitor. Try this, for example


void setup()
{
    Serial.begin(115200);
    char buffer[100];                                                //the output buffer
    int data = 123;                                                  //some example data
    sprintf(buffer, "The value of the data variable is \"%d\"", data);  //format the output with quotes round the data
    Serial.print(buffer);                                            //output the string
}

void loop()
{
}

Note how the quotation marks in the string have been escaped by using the backslash character.

oke but how i put the data into a label or textfield ?

Put whatever text you need to build up the HTML in the outer quotation marks of the second parameter of the sprintf() function

WARNING the size of the buffer needs to be large enough to hold all of the text that you put in it plus 1 character for the terminating '\0' that sprintf() will add so declare it accordingly

You can do something like below (where data is your actual variable)

client.print("<textarea font-size: 40px'; placeholder= '");
client.print(data);
client.println("' ");

Note:
The number of single ticks in client.println("<textarea font-size: 40px'; placeholder= 'data' "); is uneven. I doubt that that is correct; I did however copy that over.

yes!!!!! it only works at the bottom of the script
If it is placed at the top, all the script below will appear in the text area

How can I prevent this

div and /div doesn't help

That sounds as though you have not written the HTML correctly

Please posts a complete example sketch that illustrates the problem. Have you tried printing the output instead of sending it to the client ? That would allow you to see exactly what is being sent

123

Thank you for trying to use code tags but you did it wrong

In the IDE, right click and select "Copy for forum" and the code tags will be added to what is copied. Post that here in a new reply. Without the code tags the forum software is interpreting some of the code as HTML tags making it difficult to make sense of your code

Where is the tag for the end of the textarea in post #14 ?

123

123

If you copied that code from the IDE the way Bob told you to, and pasted it into your message, it wouldn't look like that. Look around the forum, see what code looks like out there. Why is yours unformatted?

@noelned
Until you can post your code in code tags as requested then I am afraid that it is going to be difficult to provide help.

The problem is almost certainly in the HTML code that you are using

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.