51 views

what is the other method we can use, when we are not using form name ( getElementById() ) in Javascript?

We can use a javascript function getElementById() in place of form name.

Example:

  1. <script>
  2. function use_of_getelement()
  3. {
  4. var text = document.getElementById(‘text_box_text’).value;
  5. alert("you have written "+text);
  6. }
  7. </script>
  8. <input id="text_box_text" type="text" value="Just Write Something" />
  9.  
  10. <input onclick="use_of_getelement()" name="button" type="button" value="Show My Text" />

Demo:

Post a Comment

You must be logged in to post a comment.