Within an web form I have a some input fields
Label 1
-
Those are not ASP.NET TextBox controls; they're HTML text inputs. To answer your question though, you would do this:
I noticed that you're setting the name instead of the ID in your example. I would use ID if you have a choice, but you can find an element by name like this:
$("input[name='Field1']").val("Hello world");
If you use an actual ASP.NET TextBox control, the solution will be a little different:
If you want to get all of the text inputs in the search1 div, you can do this:
$(".forminput input[type='text']").val("Hello world!");
Here's a jsFiddle for the above example: http://jsfiddle.net/DWYTR/
EDIT
Per your comment, here is how you can copy a value from one input to another on blur:
$(".forminput input[type='text']").blur(function(){
var txt = $("#<%=TextBox1.ClientID%>");
if (txt){
txt.val(txt.val() + $(this).val());
}
});
讨论(0)