Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

I cannot find the name of a dynamically created javascript object (in jQuery) -


i have page uses javascript add textboxes page, , try work based on these later.

what having lot of trouble though cannot return 'name' value saving js.

full page source (albeit simplified version) 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 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 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 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 can see, document.ready runs , creates 1 textbox. when blur fires (box loses focus) - can access id, class, type, etc, cannot value 'name'.

sure dead simple, can tell me why?

when create <input> elements ie, have this:

var txtbox = document.createelement('<input name="' + namekey + '">'); 

ie doesn't changing "name" attribute of <input> once exists, have tell you're going in call "createelement()".

one might wonder why you're not using jquery build dynamic content, since you've loading anyway.

(edit thought "type" attribute, think it's "name".)


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -