开发者

call a script with the current value of a <textarea> when the user pushes submit?

开发者 https://www.devze.com 2023-02-12 05:25 出处:网络
i\'开发者_StackOverflow社区m making a html document with a simple form on it, when the user presses submit i want to call a function that takes the value of the textarea field and does some magic on i

i'开发者_StackOverflow社区m making a html document with a simple form on it, when the user presses submit i want to call a function that takes the value of the textarea field and does some magic on it, i've had a search on w3schools and done some google digging but i just can't find anything!

update: i want them to be able to enter information over and over again, basically i'm taking what they enter, changing the formatting, adding some things .etc and writing it to the page, then i want to clear the textarea all fresh again.


<html>
<head>
<script type="text/javascript">
    function magic(){
        var textArea =document.forms[0].elements['myText'];
        textArea.style.color = 'red';
        alert(textArea.value)
    }
</script>
</head>

<body>
    <form>
        <textarea name="myText"></textarea><br/>
        <input type="button" onclick="magic()" value="Go"/>
    </form>
</body>
</html>

Hi, this bit of code should give you an idea of how you can grab the value of an input element and then manipulate it using js. I hope this is helpful :)


document.forms[0].onsubmit = function ( event ) {
    return !!prompt( this.getElementsByTagName('textarea')[0].value );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号