SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is inner html elements can recognised by form or not ?

    Hi,

    In my web page, iam trying to show the form elements dynamically.
    when user clicks on lets say link-1, then i have to show the text box and button. and i done like this:

    document.getElementById(divall).innerHTML=
    '<textarea name="message" cols="80" rows="2"></textarea>
    <input type="button" class="button" name="messagebutton" value="Send" onclick="send(this.form,id)";/>'

    Here, textarea is not recognised by the form.
    Is inner html elements can recognised by form or not ?
    Thanks in advance.

    Regards,
    Mohan

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see why this is the case. The element is part of the dom, although it would be better to use createElement when adding items to the page. This way you can pretty much guarantee they are part of the dom.


  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    It might work if you put quotes around 'divall' and avoid putting a linebreak in the middle of the string.

    A more standards-based way of creating elements is as follows:

    Code javascript:
    var els = document.createDocumentFragment(),
        el;
    el = document.createElement('textarea');
    el.setAttribute('name', 'message');
    el.setAttribute('cols', '80');
    el.setAttribute('rows', '2');
    els.appendChild(el);
    el = document.createElement('input');
    el.setAttribute('type', 'button');
    el.setAttribute('name', 'messagebutton');
    el.setAttribute('value', 'Send');
    el.className = 'button';
    el.onclick = function () {
    	send(this.form, id);
    };
    els.appendChild(el);
    document.getElementById('divall').appendChild(els);

    Needless to say, frameworks like jquery provide much easier ways to create elements and their attributes.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •