LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Javascript :: Alliteration Text Box (https://www.linuxquestions.org/questions/programming-9/javascript-alliteration-text-box-4175463742/)

cin_ 05-28-2013 05:32 AM

Javascript :: Alliteration Text Box
 
I am trying to make a text box on a webUI force the user to use alliteration. I know how have the user input text and check it to see if it follows the rules of alliteration, but how could I be constantly checking the user's input?

As the person types I determine if the last character was a space, if so then the next character must be the same as the first from the previous word, if they type that letter then proceed, if not then leave blank.

Can I run active dynamic Javascript like this?

vmccord 05-28-2013 09:20 AM

Yes, you could do this via Javascript. I'd also look into jquery. JQuery would be easier to implement. I think the thing to remember is to evaluate the value at input. If you Google "validate, textbox, and jQuery" you'll get a ton of examples. I liked this one specifically because it is at input rather than at form submit.

http://stackoverflow.com/questions/1...nt-has-changed

cin_ 05-30-2013 01:29 AM

Figured
 
vmccord, thanks for the reply. This led me on to what I was looking for.

Code:

<html>

<script type="text/javascript">

$(document).ready(function() {

    $('textarea.tecksd').on('keyup change', function() {
        $('p.dispd').text('your text: ' + $(this).val());
    });       
});

</script>

<body>
<textarea class="tecksd" placeholder="begin typing here..." id="my_text"></textarea>

<p class="dispd">your text: </p>

</body>
</html>



All times are GMT -5. The time now is 01:41 PM.