Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3624148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:28:18+00:00 2026-05-18T23:28:18+00:00

I have a page which uses javascript to add some textboxes to the page,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:28:18+00:00Added an answer on May 18, 2026 at 11:28 pm

    When you create <input> elements with IE, you have to do it like this:

    var txtbox = document.createElement('<input name="' + NameKey + '">');
    

    IE doesn’t like you changing the “name” attribute of an <input> once it exists, so you have to tell it what you’re going to do in the call to “createElement()”.

    One might wonder why you’re not using jQuery to build your dynamic content, since you’ve loading it anyway.

    (edit I thought it was the “type” attribute, but now I think it’s “name”.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system that uses a meta refresh to a logout page, which
I have a page which spawns a popup browser window. I have a JavaScript
I have a page which does quite a bit of work and I don't
I have a page which work like a navigation and a iframe in this
I am trying to modify my Javascript page, which uses Ext Js library.(I don't
I have a page which is largely created by DOM script, which generates a
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I have a page which dynamically loads a section of content via AJAX. I'm
I have a page which has a rectangular area with text and icons in
I basically have a page which shows a processing screen which has been flushed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.