Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: JavaScript Problem  (Read 3934 times)

0 Members and 1 Guest are viewing this topic.

avikumar333398

    Topic Starter


    Newbie
    • Experience: Familiar
    • OS: Windows 7
    JavaScript Problem
    « on: July 18, 2014, 11:36:41 AM »
    Can anyone give me the solution of below problem.....
    i have created following html web-page..
    the problem is that when i click transfer button it copy data from box 1 to box 2.Thats fine....
    but when i click clear button it does not empty the value of box 1.
    Why, if there is an error in my coding please write the solution soon, please write the easiest methods to do it, i have my first try on javascript.

    <html>
    <head>
    <script>

    document.writeln(hifi())
    function hifi()
       {
             var time = new Date
             var avinash = "The current Time is " +  time.getHours() + ":" + time.getMinutes() 
             return(avinash)
        }
    </script>
    <script>

    function fool()
       {
          var access
          
          access = document.form1.Text.value ;
          document.form1.Text2.value = access ;
       }

    function clearthis()
            {
                   clear(document.form1.Text.value);
             }
    </script>
    </head>
    <body>

    <h2 align="center">
    !!!!Content Mover!!!!
    </h2>
    <h3>Instructions to use the application:-</h3>
    <p>Firstly you have to enter data in Box1 then, Click the Transfer button to transfer data from Box1 to Box2.</p>
    <p>Use Clear button to clear text from box 1</p>
    <BUTTON onclick="fool()">Transfer</BUTTON>
    <BUTTON onclick="clearthis()">Clear</BUTTON>
    <form name="form1">
    Box1:<input maxlength="100" type="text" name="Text" value="" >
    Box2:<input maxlength="100" type="text" name="Text2" value="" >
    </form>
    </body>
    </html>


    please run this script in your own browser and give solution immediately
    « Last Edit: July 18, 2014, 11:47:08 AM by avikumar333398 »

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: JavaScript Problem
    « Reply #1 on: July 19, 2014, 03:04:03 PM »
    Here is the fix. It assigns the value of null space of '' to Box 1 by this method below, so the Clear function clears Box 1's contents through replacement with null space. You can even pass this null space to the box 2 with the transfer:

    function clearthis()
            {
                   clear(document.form1.Text.value ='');
                   
             }


    Code: [Select]
    <html>
    <head>
    <script>
    document.writeln(hifi())
    function hifi()
       {
             var time = new Date
             var avinash = "The current Time is " +  time.getHours() + ":" + time.getMinutes() 
             return(avinash)
        }
    </script>
    <script>
    function fool()
       {
          var access
         
          access = document.form1.Text.value ;
          document.form1.Text2.value = access ;
       }

    function clearthis()
            {
                   clear(document.form1.Text.value ='');
                   
             }
    </script>
    </head>
    <body>
    <h2 align="center">
    !!!!Content Mover!!!!
    </h2>
    <h3>Instructions to use the application:-</h3>
    <p>Firstly you have to enter data in Box1 then, Click the Transfer button to transfer data from Box1 to Box2.</p>
    <p>Use Clear button to clear text from box 1</p>
    <BUTTON onclick="fool()">Transfer</BUTTON>
    <BUTTON onclick="clearthis()">Clear</BUTTON>
    <form name="form1">
    Box1:<input maxlength="100" type="text" name="Text" value="" >
    Box2:<input maxlength="100" type="text" name="Text2" value="" >
    </form>
    </body>
    </html>