Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript UCase Function 1

Status
Not open for further replies.

SimonFinn

Programmer
Mar 13, 2003
130
GB
Hi Guys,

Can anyone point me to a bit of code that changes all characters of a word to lowercase and the inital character to upper case.

Thanks Si
 
try this:
var text = "FIRSTNAME";
text = text.toLowerCase(text);
text = text.charAt(0).toUpperCase() + text.substring(1, text.length);

hope it helps :)

(-:
 
Thanks, that was ideal...

Sorry to ask an unrelated question but i have but i am using this code to move items between select boxes but it only moves one at a time, is there any way i can change it to move all items in a multiselect?

Thanks Si

function moveIt(action, thisOption){
if (thisOption == -1){
return false;
}
if (action == 'add'){
c2 = document.getElementById("clients2")
c2.options[c2.options.length] = new Option (document.myForm.clients1[thisOption].text, document.myForm.clients1[thisOption].value)
c1 = document.getElementById("clients1")
c1.options[thisOption] = null
}
if (action == 'del'){
c1 = document.getElementById("clients1")
c1.options[c1.options.length] = new Option (document.myForm.clients2[thisOption].text, document.myForm.clients2[thisOption].value)
c2 = document.getElementById("clients2")
c2.options[thisOption] = null
}
}
function selectAll(list)
{
var opt=list.options;
for (var i=0; i<opt.length; i++) opt.selected=true;
}
 
can you submit all the html or giev a link to see this in action? i need to see everything together to understand what you're trying to do :)

(-:
 
Sorry,

I will post the code as it is on a secure site:

Here are the select boxes and the buttons that call the function:

<P align=center><SELECT id=clients1 style=&quot;WIDTH: 160px; COLOR: black; HEIGHT: 266px&quot; multiple size=5 name=clients1><%=optionStr%></SELECT> </P></TD>
<TD width=250>
<CENTER><INPUT onclick=&quot;moveSelectedOptions document.myForm.clients1, document.myForm.clients2)&quot; type=button value=&quot; < < Include&quot; style=&quot;WIDTH: 85px; HEIGHT: 22px&quot; size=69></CENTER>
<CENTER>&nbsp;</CENTER>
<CENTER><INPUT onclick=&quot;moveSelectedOptions(document.myForm.clients2, document.myForm.clients1)&quot; type=button value=&quot;Exclude > > &quot; style=&quot;LEFT: 11px; WIDTH: 85px; TOP: 136px; HEIGHT: 22px&quot; size=68 id=button1 name=button1>&nbsp;
</CENTER></TD>
<TD align=middle width=313>
<P align=center><SELECT id=&quot;clients2&quot; style=&quot;WIDTH: 160px; COLOR: black; HEIGHT: 264px&quot; multiple size=5 name=clients2><%=option2Str%></SELECT> </P></TD></TR>


If you need all the code i will post it, but i thought i will try a smaller amount first

Thanks Si
 
sorry i posted the wrong code, here is is:

<P align=center><SELECT id=clients1 style=&quot;WIDTH: 160px; COLOR: black; HEIGHT: 266px&quot; multiple size=5 name=clients1><%=optionStr%></SELECT> </P></TD>
<TD width=250>
<CENTER><INPUT onclick=&quot;moveIt('del',document.myForm.clients2.selectedIndex)&quot; type=button value=&quot; < < Include&quot; style=&quot;WIDTH: 85px; HEIGHT: 22px&quot; size=69></CENTER>
<CENTER>&nbsp;</CENTER>
<CENTER><INPUT onclick=&quot;moveIt('add',document.myForm.clients1.selectedIndex)&quot; type=button value=&quot;Exclude > > &quot; style=&quot;LEFT: 11px; WIDTH: 85px; TOP: 136px; HEIGHT: 22px&quot; size=68 id=button1 name=button1>&nbsp;
</CENTER></TD>
<TD align=middle width=313>
<P align=center><SELECT id=&quot;clients2&quot; style=&quot;WIDTH: 160px; COLOR: black; HEIGHT: 264px&quot; multiple size=5 name=clients2><%=option2Str%></SELECT> </P></TD></TR>
 
ok, i had to modify your script a little :)
here's the javascript to use (i left the function selectAll though my script has no use of it):

Code:
<script>
function moveIt(action){
	if (action == 'add'){
		addTo = document.myForm.clients2;
		removeFrom = document.myForm.clients1;
		}
	if (action == 'del'){
		addTo = document.myForm.clients1;
		removeFrom = document.myForm.clients2;
		}
	for (var i = removeFrom.options.length - 1; i >= 0; i--) {
		if ((removeFrom.options[i] != null) && (removeFrom.options[i].selected == true)) {
			addTo.options[addTo.options.length] = new Option (removeFrom[i].text, removeFrom[i].value);
			removeFrom.options[i] = null;
		}
	}
}

function selectAll(list) {
    var opt=list.options;
    for (var i=0; i<opt.length; i++) opt.selected=true;
}
</script>

here's the html (what i changed i put in bold!)
Code:
            <P align=center><SELECT id=clients1 style=&quot;WIDTH: 160px; COLOR: black; HEIGHT: 266px&quot;  multiple size=5 name=clients1><%=optionStr%></SELECT> </P></TD>
          <TD width=250>
            <CENTER><INPUT
Code:
onclick=&quot;moveIt('del')&quot;
[/code] type=button value=&quot; < < Include&quot; style=&quot;WIDTH: 85px; HEIGHT: 22px&quot; size=69></CENTER>
<CENTER> </CENTER>
<CENTER><INPUT [/code]
Code:
onclick=&quot;moveIt('add')&quot;
[/code] type=button value=&quot;Exclude > > &quot; style=&quot;LEFT: 11px; WIDTH: 85px; TOP: 136px; HEIGHT: 22px&quot; size=68 id=button1 name=button1>
</CENTER></TD>
<TD align=middle width=313>
<P align=center><SELECT id=&quot;clients2&quot; style=&quot;WIDTH: 160px; COLOR: black; HEIGHT: 264px&quot; multiple size=5 name=clients2><%=option2Str%></SELECT> </P></TD></TR>
[/code]

(-:
 
Cool, thanks for that it works a treat!!!

You've made my life a lot easier!

Cheers Si
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top