Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add ucwords and strtolower to this form

Tags:

javascript

I want "s.value" to be turned all to lowercase and then ucwords to it but I don't know how to do it since it's inside a 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

like image 796
lisovaccaro Avatar asked Jan 05 '11 21:01

lisovaccaro


People also ask

What does Ucwords mean in PHP?

The ucwords() function converts the first character of each word in a string to uppercase. Note: This function is binary-safe. Related functions: ucfirst() - converts the first character of a string to uppercase. lcfirst() - converts the first character of a string to lowercase.

How to capitalize words in php?

The strtoupper() function converts a string to uppercase.

How to first letter capital in php?

The ucfirst() function converts the first character of a string to uppercase. Related functions: lcfirst() - converts the first character of a string to lowercase. ucwords() - converts the first character of each word in a string to uppercase.


1 Answers

<script type="text/javascript">

function ucwords (str) {
    return (str + '').replace(/^([a-z])|\s+([a-z])/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;" >

The javascript functions are from PHP.JS

like image 88
Saul Avatar answered Oct 03 '22 08:10

Saul