How to add ucwords and strtolower to this form

I want s.value to be flipped all in lowercase and then ucwords, but I donโ€™t know how to do this since it is inside the form.

Basically I want to do something like this: ucwords (strtolower (s.value here));

This is the form:

<form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="if (document.getElementById('s2').value.length > 5) window.location = action + '<php echo $city; ?>++++' + s.value; return false;" > 

thanks

+4
source share
7 answers
 <script type="text/javascript"> function ucwords (str) { return (str + '').replace(/^([az])|\s+([az])/g, function ($1) { return $1.toUpperCase(); }); } function strtolower (str) { return (str+'').toLowerCase(); } </script> <form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="if (document.getElementById('s2').value.length > 5) window.location = action + '<?php echo $city; ?>++++' + ucwords(strtolower(s.value)); return false;" > 

Javascript functions: php.js

+20
source

Javascript String has two functions: toLowerCase () and toUpperCase, you can use them with

 function toInitCap(input) { input = input || ""; return input.substring(0,1).toUpperCase() + input.substring(1,str.length).toLowerCase(); } toInitCap(s.value) 
+3
source

You can, like me, want something that does this on one line, I used:

 "your strING".toLowerCase().replace(/(?:(^.{1})|\ [az]{1})/g, function(a){return a.toUpperCase();}) 

returns Your String

+2
source
 + <?php echo ucwords(strtolower($s_value)); ?>; 
+1
source

You want to do:

 $out = ucwords(strtolower($_GET['s.value'])); 

If s.value is the login name you want to pass

0
source

If you want to do this while they are editing text in a text box, I'm not sure what you will do, but if you want to make it lowercase and then in upper case AFTER they submit the form, then it's simple.

ucwords (strtolower ($ _ GET ['FormID']))

0
source

str.length => input.length

 function toInitCap(input) { input = input || ""; return input.substring(0,1).toUpperCase() + input.substring(1,input.length).toLowerCase(); } toInitCap(s.value) 
0
source

Source: https://habr.com/ru/post/1334430/


All Articles