error: when i try to add <form tag
below is my html form and i dont get any error if i dont have a <form
tag, so i add a form tag like this:
<form class="cmxform" id="commentForm" method="post" action="">
get this error:
Microsoft JScript runtime error: 'first_name' is undefined
when i try to read the value of a text box:
First Name:
<input id="first_name" class=" text hasCorners required" maxlength="200"
name="first_name" />
function PostData() {
var _firstName = first_name.value;
......
......
$(document).ready(function () {
$('#btnRegister').click(function () {
PostData();
});
Try:
var _firstName = $('#first_name').val();
Seems like you need to specify the form element's ID first:
commentForm.first_name.value;
Not sure why though.
EDIT: To clarify, this resolves the IE issue with the technique you were using. As @bobince noted in the comment below, accessing IDs as global properties is not safe unless you're targeting specific browsers.
Based on the code in your question and your comment under another answer, it appears that you already know how to select by ID using jQuery and getElementById
.
精彩评论