...

View Full Version : My First JavaScript



AhmadWaqas
09-28-2011, 09:21 PM
OK .. Solved ... there was a typing mistake in the code :)

Today is my first day to start learning JavaScript. When i try to run the following code (copy-paste from a book), the browser gives me an error. Can you please tell me what's wrong with the following code:


<HTML>
<HEAD>
<SCRIPT LANGUAGE = "JavaScript">
function upperMe(){
document.converter.output.value = document.converter.input.value.toUpperCase()
}
</SCRIPT>
</HEAD>

<BODY>
<FORM NAME = "converter">
<INPUT TYPE = "text" NAME = "input" VALUE="sample" onChange="upperMe()">
<INPUT TYPE = "text" NAME = "output" VALUE="sdf">
</FORM>
</BODY>
</HTML>


Thanks
Ahmad

ironboy
09-28-2011, 09:29 PM
Also consider using document.forms instead of just document
It's clearer and more standard compliant.

document.forms.converter ... etc:)

Philip M
09-29-2011, 07:29 AM
<script language="javascript"> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.

xelawho
09-29-2011, 02:25 PM
I would also consider using onkeyup for this type of operation:
<INPUT TYPE = "text" NAME = "input" VALUE="sample" onkeyup="upperMe()">

onchange doesn't quite cut it for me, although I know it has its place...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum