Heena Rajshree
Heena Rajshree

Reputation: 89

How to pass a variable from HTML to Java?

I want to pass a variable from HTML to Java. For this, I wrote the following code:

<!doctype html>
<html>


    <title>How to create a typewriter or typing effect with jQuery</title>
    <div id="example1">fsdfsdfojsdlk sdfj lskdhfk sdf </div>
    <style>
        body{

    background: transparent;

    color: #ec5a62;

        }

        #container{
            font-size: 7em;
        }  

    </style>

</head>
<body>

    <div id="container"></div>

    <!-- 
        We use Google's CDN to serve the jQuery js libs. 
        To speed up the page load we put these scripts at the bottom of the page 
    -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

    <script>

        //define text
 var text = ("document.getElementById("example1")");

        //text is split up to letters
        $.each(text.split(''), function(i, letter){

            //we add 100*i ms delay to each letter 
            setTimeout(function(){

                //we add the letter to the container
                $('#container').html($('#container').html() + letter);

            }, 30*i);
        });

    </script>

</body>
</html>

But it is not working. How can I achieve this?

Please do help me.

I'm using var text =("document.getElementById("example1")");

But its not working.

Upvotes: 1

Views: 1587

Answers (1)

Faisal Hameed
Faisal Hameed

Reputation: 104

to get value use var x=document.getElementById("example1").value;

your code should be like this:

var text=document.getElementById("example1").value;
 //text is split up to letters
    $.each(text.split(''), function(i, letter){

        //we add 100*i ms delay to each letter 
        setTimeout(function(){

            //we add the letter to the container
            $('#container').html($('#container').html() + letter);

        }, 30*i);
    });

Upvotes: 1

Related Questions