Moving Text in TextBox using JavaScript in Bootstrap

In this tutorial, we are going to learn how to create Moving Text in TextBox using JavaScript in Bootstrap. This simple project, text in a textbox that automatically scrolling in itself and it is created using JavaScript query and for the GUI using Bootstrap Template. You can use this simple project to catch the attention of the users while they visiting your site. It's used as your alert message or a kind of special announcement for the users to catch them easily that you have a message for them. For the Live Demo, kindly click the button below. Bootstrap File If you have already Bootstrap File in your computer, kindly unzip this compressed file folder to have it and to see what's the structure of the Bootstrap File. It looks like this:
  1. bootstrap/
  2. ├── css/
  3. │   ├── bootstrap.css
  4. │   ├── bootstrap.css.map
  5. │   ├── bootstrap.min.css
  6. │   ├── bootstrap.min.css.map
  7. │   ├── bootstrap-theme.css
  8. │   ├── bootstrap-theme.css.map
  9. │   ├── bootstrap-theme.min.css
  10. │   └── bootstrap-theme.min.css.map
  11. ├── js/
  12. │   ├── bootstrap.js
  13. │   └── bootstrap.min.js
  14. └── fonts/
  15.     ├── glyphicons-halflings-regular.eot
  16.     ├── glyphicons-halflings-regular.svg
  17.     ├── glyphicons-halflings-regular.ttf
  18.     ├── glyphicons-halflings-regular.woff
  19.     └── glyphicons-halflings-regular.woff2
Create Markup Then, we are going to create a simple markup for the text scrolling in the TextBox. Copy and paste this source code to the BODY tag of your web page.
  1. <form name="text_Marquee">
  2.    <input name="text" class="form-control"
  3.      value=" Welcome to Sourcecodester..... Do you have a source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.... Submit now!!! "  disabled />
  4. </form>
Construct Simple Script This simple script helps us to move the text in the TextBox. You can set the scrolling speed whatever you want, you can change it in the speed_Scrolling variable in the simple script. Take a look the source code below and study it.
  1. <script>
  2.     /*
  3.     Text box marquee,
  4.     You can used/modified if credit
  5.     line is retained
  6.     */
  7.     speed_Scrolling = 150
  8.     characters_Scroll = 1
  9.  
  10.     function scrolling_Text() {
  11.         window.setTimeout('scrolling_Text()', speed_Scrolling);
  12.  
  13.         var msg = document.text_Marquee.text.value;
  14.         document.text_Marquee.text.value =
  15.             msg.substring(characters_Scroll) +
  16.             msg.substring(0, characters_Scroll);
  17.     }
  18.     scrolling_Text()
  19. </script>

Output

Result If you are comfortable with the source code, then kindly download the source code below via click the "Download Code" button. Then, unzip the file to see all the source code. Thank you, enjoy coding.

Add new comment