Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Jquery Setting Value of Input Field

Writer Sophia Terry

I have an input field and i am trying to set its value using its class

<form:input path="userName" title="Choose A Unique UserName" readonly="${userNameStatus}"/>

Which renders as:

<input name="userName" title="Choose A Unique UserName" type="text" value=""/>

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

$(".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.

12

7 Answers

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(""); });
})
<script src=""></script>
<input type="text" value="yoyoyo">
<button>Click Here to reset</button>
1

If the input field has a class name formData use this :$(".formData").val("data")

If the input field has an id attribute name formData use this :$("#formData").val("data")

If the input name is given use this :$("input[name='formData']").val("data")

You can also mention the type. Then it will refer to all the inputs of that type and the given class name:$("input[type='text'].formData").val("data")

change your jquery loading setting to onload in jsfiddle . . .it works . . .

2

use this code for set value in input tag by another id.

$(".formdata").val(document.getElementById("fsd").innerHTML);

or use this code for set value in input tag using classname="formdata"

$(".formdata").val("hello");
$('.formData').attr('value','YOUR_VALUE')

You just write this script. use input element for this.

$("input").val("valuesgoeshere"); 

or by you write this code.

$("input").val(document.getElementById("fsd").innerHTML);

Put your jQuery function in

$(document).ready(function(){
});

It's surely solved.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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