Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    23
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Writing a form in javascript

    PHP Code:
    1document.write("<input type='text' name='' value=''>");
    2document.write('<input type="text" name="" value="">');
    3document.write("<input type=\"text\" name=\"\" value=\"\">"); 
    Is there any other way to make an input using document.write.
    I need atleast 4 diferent ways for a project...

    ===============================================

    Stop saying document.write is outdated because it's so usefull.

  • #2
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Code:
    var inpt = '<input type="text" name="" value="">';
    document.write(inpt);
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,985
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by low tech View Post
    Code:
    var inpt = '<input type="text" name="" value="">';
    document.write(inpt);
    Aaarrrgggghhhh! document.write is obsolete!!! What is this project? Some sort of homework?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Quote Originally Posted by Electrify View Post
    Stop saying document.write is outdated because it's so usefull.
    Only because you don't know the right way to do things.

    There are still a bare handful of things document.write could/should be used for. Creating <form> fields is *NOT* one of them.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Quote Originally Posted by Philip M View Post
    Aaarrrgggghhhh! document.write is obsolete!!! What is this project? Some sort of homework?
    Of course it's homework. For a really dumb class. For an instructor completely out of touch with the times. There's no other excuse for having such a "project". You have to wonder if all these students think we are total idiots to believe that their dirt simple and outdated "projects" are anything except homework of the worst kind.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Here, since we are coming up with all the dumbest possible ways to do things:
    Code:
    var inpt = '<input type="text" name="" value="">';
    for ( var i = 0; i < inpt.length; ++i )
    {
        document.write(inpt.charAt(i));
    }
    or
    Code:
    var rev = '>""=eulav ""=eman "txet"=epyt tupni<';
    document.write( rev.split("").reverse().join("") );
    How many more silly-azzed ways do you want us to come up with?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by Old Pedant View Post
    How many more silly-azzed ways do you want us to come up with?
    I'll admit, I didn't add into this conversation because it feels dirty a) typing out multiple ways to add an input, and b) using document.write to do it.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by Electrify View Post
    Stop saying document.write is outdated because it's so usefull.
    document.write is completely obsolete because it iis so UNuseful and requires so much code to fix it. ONLY use it if your visitors use Netscape 4 and earlier - it has no place in more modern browsers such as Internet Explorer Five.

    See http://www.felgall.com/jstip146.htm for how to get JavaScript to generate extremely complex forms with minimal code - by actually using JavaScript properly to create an object that contains methods for generating each field type.

    Don't forget to put all the JavaScript just before the </body> tag where it belongs. - one reason why document.write is dead - because it breaks when you attach the script at the right spot.

    If you absolutely MUST use document.,write then simply leave out everything up to and including the opening " or " and everything after and including the closing " or ' - ie, use HTML without the unnecessary script wrapper.
    Last edited by felgall; 08-16-2013 at 10:06 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New Coder
    Join Date
    May 2013
    Posts
    23
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Aaarrrgggghhhh! document.write is obsolete!!! What is this project? Some sort of homework?
    no, 100% malicious use

  • #10
    New Coder
    Join Date
    May 2013
    Posts
    23
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by low tech View Post
    Code:
    var inpt = '<input type="text" name="" value="">';
    document.write(inpt);
    Doesn't work in the project but thanks

  • #11
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by Electrify View Post
    Is there any other way to make an input using document.write.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<meta http-equiv="content-type" content="application/sgml; charset=utf-8">
    	<meta name="keywords" content="anachronism, 1999">
    	<title>Demo</title>
    	<style type="text/css">
    		input { width: 500px; }
    	</style>
    	<div>
    		<script type="application/javascript">
    			eval("document['write']('<input text value=\\'Welcome to 1999!\\'<![IGNORE[THIS]]><button button>Decorative Button<\\/>');");
    		</script>
    	</div>
    	<p><a href="http://validator.w3.org/check?uri=referer"><img alt="Valid HTML 4.01 Strict" width="88" height="31" src="http://www.w3.org/Icons/valid-html401"></a>
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

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