Reply
how to create textbox using javascript?
Old 06-16-2008, 03:52 AM how to create textbox using javascript?
Novice Talker

Posts: 8
Name: paparanch
hey guyz!

i have another question for you guyz!

is thier a way to create a textbox using javasccript?

just like this one in html <input type="text"...blah blah...></input>

what is the equivalent code of this in javascript?
paparanch is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-16-2008, 05:21 AM Re: how to create textbox using javascript?
nyef's Avatar
Ultra Talker

Posts: 267
Name: Lucas
Code:
document.write("<input type=\"text\"...blah blah...></input>");
or
Code:
document.getElementById("somediv").innerHTML="<input type=\"text\"...blah blah...></input>";
__________________
~nyef
Over 5000 free games!
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-17-2008, 05:16 PM Re: how to create textbox using javascript?
Gilligan's Avatar
Dead Like Me

Posts: 1,618
Name: Stefan
Location: London, UK
... there's no such thing as </input>
__________________
Offering Website Design Worldwide, please visit my website
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 06-19-2008, 12:44 AM Re: how to create textbox using javascript?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 995
Name: Jeremy Miller
Location: Reno, NV
You will want to use DOM-compliant methodologies. This generalized function should help. The third parameter is an inline object of the form

Code:
{parameter_name:'parameter_value', ...}
Where parameter_name is intentionally not quoted (though, it may be, if desired) and the value is quoted. The colon between them is required. Separated by a comma, you can add as many as you want.

HTML Code:
<html>
  <head>
    <script>
      function addElement(tag_type, target, parameters) {
        //Create element
        var newElement = document.createElement(tag_type);

        //Add parameters
        if (typeof parameters != 'undefined') {
          for (parameter_name in parameters) {
            newElement.setAttribute(parameter_name, parameters[parameter_name]);
          }
        }

        //Append element to target
        document.getElementById(target).appendChild(newElement);
      }
    </script>
  </head>
  <body>
    <div id="targetTag"></div>
    <input type="button" onClick="addElement('INPUT','targetTag',{id:'my_input_tag', name:'my_input_tag', type:'text', size:'5'}); return false;" value="Add Input Tag" />
    <input type="button" onClick="addElement('INPUT','targetTag'); return false;" value="Add Input Tag W/O Parameters" />
  </body>
</html>
EDIT: One note. If you bother to check the DOM after executing this in IE, you'll see that the name field is not available to you. IE declares this field to be read-only which is why you don't see it. The field will be properly submitted, however, as shown in this test code:

PHP Code:
<?php
if (isset($_POST)) {
  print 
'<pre>'.print_r($_POST,true).'</pre>';
}
?>
<html>
  <head>
    <script>
      function addElement(tag_type, target, parameters) {
        //Create element
        var newElement = document.createElement(tag_type);

        //Add parameters
        if (typeof parameters != 'undefined') {
          for (parameter_name in parameters) {
            newElement.setAttribute(parameter_name, parameters[parameter_name]);
          }
        }

        //Append element to target
        document.getElementById(target).appendChild(newElement);
      }
    </script>
  </head>
  <body>
    <form method="post">
    <div id="targetTag"></div>
    <input type="submit" value="Check"/>
    </form>
    <input type="button" onClick="addElement('INPUT','targetTag',{'id':'my_input_tag', 'name':'my_input_tag', 'type':'text', 'size':'5'}); return false;" value="Add Input Tag" />
    <input type="button" onClick="addElement('INPUT','targetTag'); return false;" value="Add Input Tag W/O Parameters" />
  </body>
</html>
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites

Last edited by JeremyMiller : 06-19-2008 at 01:05 AM.
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to how to create textbox using javascript?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12580 seconds with 12 queries