开发者

how to set character to big size without press capslock

dear all..i want my input form automatically make all character become big size.. and also without press a capslock but开发者_C百科ton...i want all data which have been input into DB in capital format..what's code to make it?


One simple way in jQuery is to convert the the value to uppercase after every keyup event:

$(document).ready(function(){
  $('#myfield').keyup(function() {
    var t = $(this);
    t.val(t.val().toUpperCase());
  });
});

Remember that this only changes the value in the UI on the client. When the user submits the form, it will send this uppercased value, but a malicious user could send data that was not uppercased, so you probably want to use an upcase method on your server, either in your CGI code (PHP, Perl, Java or whatever you're using), or in your SQL insert statement.


As Matthew said, strtoupper() will work.


$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO

Using Javascript to filter something that is going into a database, is bad. What if the user decides to turn of Javascript? You can do it, but it will have to be done again when in the backend code, so it's a waste of time for something like this :)


You can use the PHP function strtoupper.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜