Reverse the characters added in text field
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts: 106
Reverse the characters added in text field
I have the following html and JavaScript code. An input text box and a button.
Code: Select all
<input type='text' id='backwards-input'>
<button id='backwards-button'>Button</button>
<p id='backwards-container'></p>
<script>
const bkinp = document.getElementById('backwards-input');
const bkbtn = document.getElementById('backwards-button');
const revtxt = document.getElementById('backwards-container');
</script>
How can I make, when I press the button, the text that is added in the input box be displayed into the <p> element, but in reverse order?
For example, if in the input is "abc 123", the text "321 cba" should be added into the <p> element from my code.
Admin
Try use and study the following code:
Code: Select all
<input type='text' id='backwards-input'>
<button id='backwards-button'>Button</button>
<p id='backwards-container'></p>
<script>
function backwards(inp, rev) {
const backwardsInput = inp.value.split('').reverse().join('');
rev.textContent = backwardsInput;
}
const bkinp = document.getElementById('backwards-input');
const bkbtn = document.getElementById('backwards-button');
const revtxt = document.getElementById('backwards-container');
bkbtn.addEventListener('click', ()=>{ backwards(bkinp, revtxt)});
</script>
Demo
Similar Topics
-
Adding content from a Div into an input text field
JavaScript - jQuery - Ajax
First post
I still don`t understand how I can get the results from a div into a text input form field ?
<div id= div2 > Content </div>
I...
Last post
Thanks Chief for all your support....
My URL-extractor is working
in the comment-system
-
Extract last N characters from a number
PHP - MySQL
First post
Hello,
I want to extract the last three characters from a number, an id.
For example:
$id ='123456';
$nid ='456'; //this i need
And, if the id...
Last post
Hello,
You can use in your php code the getNId() function from the following example.
It returns the first or the last $n characters from a number...
-
How to display in php special characters from mysql
PHP - MySQL
First post
I prefer not to bother you too often but because of my bad English, two accounts have already been blocked on stack overflow.
And I think you are...
Last post
Try this:
- At the beginning of your php script, for example at the beginning of the configuration.php file add the header function for utf-8...
-
Show with animation the content added with JavaScript
JavaScript - jQuery - Ajax
First post
The idea is that when i click on a button, old content gets replaced by new HTML content added with javascript.
I want that new content to appear...
Last post
To trigger a CSS transition, change the CSS state after you inserted the HTML. You can do this by changing a class (on the container or an inserted...
-
Concatenate field value in replace() mysql
PHP - MySQL
First post
Hello,
How can I concatenate the value of a string in the replace() statement in mysql?
For example, in the 'content' column i have something...
Last post
Hi,
You can use the concat() function in the replace() statement.
REPLACE(col_name, concat('string', col_2, 'join-string'), 'new_value')
- Here...