Jquery Setting Value Of Input Field

I am using the following jquery but this does not seem lớn work. Can someone tell me where i am going wrong.

Bạn đang xem: Jquery setting value of input field

$(".formData").html("");Edited JQuery Function that handles the event

$("#reset").click(function () $("#userNameErr").text(""); $("#badgeNoErr").text(""); $(".errors").html(""); $(".formData").val(""); );nor is $(".formData").text("") or $(".formData").val("") working.


*

Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)

Help us improve our answers.

Are the answers below sorted in a way that puts the best answer at or near the top?


If the input đầu vào field has a class name formData use this :$(".formData").val("data")

If the đầu vào field has an id attribute name formData use this :$("#formData").val("data")

If the input name is given use this :$("input").val("data")

You can also mention the type. Then it will refer to lớn all the inputs of that type & the given class name:$("input.formData").val("data")


*

This should work.

$(".formData").val("valuesgoeshere")For empty

$(".formData").val("")If this does not work, you should post a jsFiddle.

Demo:
$(function() $(".resetInput").on("click", function() $(".formData").val(""); );)Click Here to reset

*

*

*

use this code for set value in đầu vào tag by another id.

Xem thêm: Những Bí Quyết Giao Tiếp Larry King, Đọc Sách Truyện Những Bí Quyết Giao Tiếp Tốt

$(".formdata").val(document.getElementById("fsd").innerHTML);oruse this code for phối value in đầu vào tag using classname="formdata"

$(".formdata").val("hello");
You just write this script. Use đầu vào element for this.

$("input").val("valuesgoeshere"); or by id="fsd" you write this code.

$("input").val(document.getElementById("fsd").innerHTML);
Thanks for contributing an answer to Stack Overflow!

Please be sure lớn answer the question. Provide details & share your research!

But avoid

Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.


Post Your Answer Discard

By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged javascript jquery html or ask your own question.


Site design / hình ảnh sản phẩm © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.4.19.41984


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.