/    Sign up×
Community /Pin to ProfileBookmark

Hi guys,wats up?
so i am trying to make this short script that will toggle my text from upper case to lowercase and from lowercase to upper case… so if i wrote HeLlO wOrLd, my script will output hElLo WoRlD. I have gave it many tries but i am just not getting it, can someone who knows what he’s doing help me out, thx! Here is a sample of my noob code:

<html>
<head>
<script type=”text/javascript”>
function togglecase(){
var theinput=document.getElementById(“output”).value;
if (theinput == theinput.toUpperCase()){
theinput.value.toLowercase();
}
else if (theinput == theinput.toLowerCase()){
theinput.value.toUpperCase();
}
}
</script>
<body>
<form>
<input type=”checkbox” onClick=”togglecase()”/>Toggle Case<br />
<input type=”text” id=”output” />
<!–Oh yeah i forgot to mention that i want my input and output to be in a textbox and the checkbox will change it (no need to toggle back and forth just once is good enough, basic script is all i need)–>
</form>
</body>
</html>

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cluefulApr 18.2011 — [CODE]<html>
<head>
<script type="text/javascript">

function togglecase( field )
{
field.value = field.value.replace( /[a-z]/ig, function( c ){ var n = c.charCodeAt(0); return String.fromCharCode( n < 97 ? n + 32 : n - 32 ); } );

}

</script>
<body>
<form>
<input type="checkbox" onClick="togglecase(output)"/>Toggle Case<br />
<input type="text" name="output" value="HeLlO wOrLd">
</form>
</body>
</html>[/CODE]
×

Success!

Help @javascriptman18 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...