Doubt for an activity

Asked

Viewed 52 times

3

3) Make a Javascript code that changes the content value of the text element to "Pedro Brigatto".

I have to change the value of that value in this input:

<!DOCTYPE html>
<html>
  <body>
    <input type="text" id="myText" value="Mudar aqui">
  </body>
</html>
  • What doubt do you have?

2 answers

5

The code could be this:

document.getElementById("myText").value = "Pedro Brigatto";

document.getElementById("myText").value = "Pedro Brigatto";
<input type="text" id="myText" value="Mudar aqui">

  • #perfect! I perfected a little further down! But your reply was much more direct! :)

  • 1

    thanks guy thanks

  • 1

    @user95806 If this answer solved your problem and you have no questions left, mark it as accepted/correct by clicking on " " here on the side, which also marks your question as answered/solved. If you prefer the other answer, then mark it (you can only mark one as accepted). If on the other hand, you are still not satisfied with any of the answers, leave a comment and we will clarify.

4

For you to select an HTML element in Javascript, seven your field with an ID, if use once, as was done in your code:

<input type="text" id="myText" value="Mudar aqui">

In this case, your ID is "myText".

In Javascript, you need to take this data and set it, just like @Dvd did in the previous answer, but who does it for you is the:

document.getElementById("AQUI VAI O SEU ID");

When you put the .value after this code, you are picking up the value of your input field. You can pick up other parameters, as I will give some examples below:

Change the class parameter:

document.getElementById("myText").class = "Pedro Brigatto";

Change the id parameter:

document.getElementById("myText").id = "Pedro Brigatto";

I hope I’ve contributed to your knowledge! :)

  • 1

    Must be className and not class. +1 for explaining the code!

  • Thanks Sergio! In mine it worked like this. But I’ll take precautions next time. I’m grateful for the feedback!

  • 1

    thanks man thanks thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.