0

From this code.

<form method="get">
    <div align="center"><textarea name="post" ></textarea></div>
    <div align="center"><input type="submit" value="Submit"></div>
</form>

<?
$aaa = $post;
$new_aaa=str_replace(array(
'a', 
'b'
), array(
'A',
'B'
), $aaa);
?>

<textarea readonly="true" cols="100" rows="3" name="post" >
    <? echo $new_aaa; ?>
</textarea>
</div>

If we write in the form of javascript to do here? If you do not understand, it is to get value from textarea and then use the str_replace function as a type, but the output is A, help me write a little PHP I own one, but never wrote JS.

Sorry for bad English, I've used Google Translate.

2
  • Do you only want to replace 'a' by 'A' and 'b' by 'B', or just make the textarea text all uppercase? Do you want to modify the textarea text when focus leaves the textarea? Commented May 14, 2011 at 0:07
  • 1
    Are you asking to convert the functionality of the above code from PHP to Javascript? Commented May 14, 2011 at 0:16

2 Answers 2

1
<form method="get" onSubmit='Convert()'>
    <div align="center"><textarea name="post" id="post" ></textarea></div>
    <div align="center"><input type="submit" value="Submit"></div>
</form>

........ In script

<script>
function Convert()
{
  var p = document.getElementById ("post").value;
 p =  p.replace(/a/g,”A”);
 p =  p.replace(/b/g,”B”);

document.getElementById ("post").value= p;

}
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

IIRC Convert() needs to return false or you won't see the result.
Now I can do then. Thank you all comments.
0

Now I can do then.

Thank you all comments.


<form method="get" onsubmit="return Convert();">
    <div align="center"><textarea name="post" id="post" ></textarea></div>
    <div align="center"><input type="submit" value="Submit"></div>
</form>

<script>
function Convert()
{

    var p = document.getElementById ("post").value;

    var replace = {
        '1' : "\u0e45",
        '2' : "\u002F",
    };
    for(var i in replace)
    {
        var regex = new RegExp(i,'g');
        p =  p.replace(regex,replace[i]);
    }
    document.getElementById ("post2").value= p;
    return false;
}
</script>
<textarea readonly="true" cols="100" rows="3" name="post2" id="post2" >
</textarea>

1 Comment

Add 4 spaces or a tab to each line of code, then you get code highlighting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.