I have a page which uses javascript to add some textboxes to the page, and then we try to do some work based on these later.
What I am having a lot of trouble with though is that I cannot return the 'name' value which I am saving with the js.
Full page source (albeit a simplified version) is below.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//we use live because the inputs havent been created yet.
$('.myclass').live('blur', function () {
//debugger;
alert('textbox selected has ID '+ $(this).attr('id') ); //this returns txtInput
alert('textbox selected has name '+ $(this).attr('name') ); //this returns null (or an empty string).
});
AddInputTextBox("My Label: ", "txtInput", "mydiv", "MyName");
});
function AddInputTextBox(LabelValue, Id, divToAddTo, NameKey) {
//debugger;
var txtbox = document.createElement('input');
txtbox.setAttribute("type", "text");
txtbox.setAttribute("id", Id);
txtbox.setAttribute("name", NameKey);
txtbox.setAttribute("class", "myclass");
alert('Textbox created with name = ' + txtbox.name);
var foo = document.getElementById(divToAddTo);
foo.innerHTML += LabelValue;
foo.appendChild(txtbox);
}
</script>
</head>
<body>
<div id="mydiv">
<!-- placeholder -->
</div>
</body>
</html>
So as you can see, document.ready runs and creates one textbox. when the blur fires (box loses focus) - I can access the ID, class, type, etc, but I cannot get a value for the 'name'.
Sure it is something dead simple, but can someone tell me why?