jeudi 13 novembre 2014

How to replace text (w/ javascript) using text from a form?


Vote count:

0




I'm trying to create "interactive" posts on my blog (tumblr) by using one-word input from the user/reader and replacing a keyword in my post with it.


Example: Post: "name has a dog."

Input: "Alice"

Post: "Alice has a dog."


I've tried to replace words using a script, but it only replaces the first word, and the rest remains the same. Do I create some sort of a loop somehow?

Plus, I still can't figure out how I'd use input from the user as the value of the replacing word. If I create a simple HTML form, how do I retrieve/use the value of the text input? Can I create variables within the script?


Here's the script I used within the post:



<script type="text/javascript"> document.body.innerHTML = document.body.innerHTML.replace('hello', 'hi'); </script>


Sorry if the questions are too obvious, but I'm new at this. Thanks.



asked 2 mins ago







How to replace text (w/ javascript) using text from a form?

Aucun commentaire:

Enregistrer un commentaire