I have an input text which is this:
<div class="editor-label">
@Html.LabelFor(model => model.EmployeeId, "Employee Number")
</div>
<div class="editor-field textBoxEmployeeNumber">
@Html.EditorFor(model => model.EmployeeId)
@Html.ValidationMessageFor(model => model.EmployeeId)
</div>
I want to set the value of this input text using jquery so i did this:
<script type="text/javascript" language="javascript">
$(function() {
$('.textBoxEmployeeNumber').val("fgg");
});
</script>
however, it is not working... what is the error in my syntax?
Your selector is retrieving the text box's surrounding
<div class='textBoxEmployeeNumber'>
instead of the input inside it.Update after seeing output HTML
If the ASP.NET code reliably outputs the HTML
<input>
with an id attributeid='EmployeeId'
, you can more simply just use:Failing this, you will need to verify in your browser's error console that you don't have other script errors causing this to fail. The first example above works correctly in this demonstration.
Using jQuery, we can use the following code:
Select by input name:
Select by input class:
Select by input id:
Here is another variation for a file upload that has a nicer looking bootstrap button than the default file upload browse button. This is the html:
Here is the script:
For element with id
You can set the value as
Documentation here.
this is for classes
for ids
now if u have an iput in a form u can use