473,769 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple JavaScript question

Please excuse this very basic question; I'm just starting to learn
JavaScript.

I have just modified added a toUpperCase statement to change strings
to upper case, but it does not run.

Can you please tell me what I have done wrong? I have pasted the code
in below.

Thank you.

-------------------------------------------------------------------------------------------------

// JavaScript Document

// initialize the counter and the array
var numnames=0;
var names = new Array();
function SortNames() {
// Get the name from the text field
SortNames toUpperCase();
//Change the names to all upper case
thename=documen t.theform.newna me.value;
// Add the name to the array
names[numnames]=thename;
// Increment the counter
numnames++;
// Sort the array
names.sort();
document.thefor m.sorted.value= names.join("\n" );

Feb 17 '07 #1
4 1494
pa************@ gmail.com wrote on 17 feb 2007 in comp.lang.javas cript:
// JavaScript Document

// initialize the counter and the array
var numnames=0;
var names = new Array();
function SortNames() {
// Get the name from the text field
SortNames toUpperCase();
The name of a function cannot return a string in itself,
[unless you programme recursive, which is not here]

toUpperCase() should be attached by a period like this:

var a = 'A StrinG';
alert( a.toUpperCase() ; ); // shows: A STRING

//Change the names to all upper case
thename=documen t.theform.newna me.value;
This could work, if the form is correctly named

better keep your variables local, and do this:

var thename =
document.forms['theform'].elements['newname'].value;

// Add the name to the array
names[numnames]=thename;
// Increment the counter
numnames++;
You forgot to define a loop, this way only names[0]
is created and assigned
// Sort the array
names.sort();
document.thefor m.sorted.value= names.join("\n" );
you will need to end the function with a }

============

If, Paul, I did not misread your intended purpose,
perhaps the tested code below will help you:

============= test.html =============== =======
<script type='text/javascript'>

function SortNames() {
var names = new Array();
var f = document.forms['theForm'];
for (var n=0;n<3;n++)
names[n] =
f.elements['elem' + n].value.toUpperC ase();
f.elements['sorted'].value =
names.sort().jo in("+");
return false;
};

</script>
<form name='theForm' onsubmit='retur n SortNames();'>
<input name='elem0' value='xyz x'><br>
<input name='elem1' value='ABC x'><br>
<input name='elem2' value='Pqr x'><br>
<input type='' name='sorted' value=''><br>
<input type='submit' value='Sort me'><br>
</form>
=============== =============== =============== ====

Are you sure I am not making your school assignment?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 17 '07 #2
On Feb 17, 11:28 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net >
wrote:
paul.denlin...@ gmail.com wrote on 17 feb 2007 in comp.lang.javas cript:
// JavaScript Document
// initialize the counter and the array
var numnames=0;
var names = new Array();
function SortNames() {
// Get the name from the text field
SortNames toUpperCase();

The name of a function cannot return a string in itself,
[unless you programme recursive, which is not here]

toUpperCase() should be attached by a period like this:

var a = 'A StrinG';
alert( a.toUpperCase() ; ); // shows: A STRING
//Change the names to all upper case
thename=documen t.theform.newna me.value;

This could work, if the form is correctly named

better keep your variables local, and do this:

var thename =
document.forms['theform'].elements['newname'].value;
// Add the name to the array
names[numnames]=thename;
// Increment the counter
numnames++;

You forgot to define a loop, this way only names[0]
is created and assigned
// Sort the array
names.sort();
document.thefor m.sorted.value= names.join("\n" );

you will need to end the function with a }

============

If, Paul, I did not misread your intended purpose,
perhaps the tested code below will help you:

============= test.html =============== =======
<script type='text/javascript'>

function SortNames() {
var names = new Array();
var f = document.forms['theForm'];
for (var n=0;n<3;n++)
names[n] =
f.elements['elem' + n].value.toUpperC ase();
f.elements['sorted'].value =
names.sort().jo in("+");
return false;

};

</script>

<form name='theForm' onsubmit='retur n SortNames();'>
<input name='elem0' value='xyz x'><br>
<input name='elem1' value='ABC x'><br>
<input name='elem2' value='Pqr x'><br>
<input type='' name='sorted' value=''><br>
<input type='submit' value='Sort me'><br>
</form>
=============== =============== =============== ====

Are you sure I am not making your school assignment?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sorry I did not give you the URL for the HTML page; it's
http://www.china-ready.com/jstest/arraysorting.htm Hope this makes
what I'm trying to do clearer.

Actually, no I'm not doing a school assignment; this is entirely self-
imposed. I'm working my way thru Sams Teach Yourself Javascript in 24
Hours. This is the exercise at the end of Hour 5.

If you have any suggestions about how to use Firebug to debug
JavaScript; I'd appreciate your input. I'm so new that I can't figure
out the debug messages.

Thanks again!

Paul

Feb 17 '07 #3
pa************@ gmail.com wrote on 17 feb 2007 in comp.lang.javas cript:
>If, Paul, I did not misread your intended purpose,
perhaps the tested code below will help you:

============ = test.html =============== =======
<script type='text/javascript'>

function SortNames() {
var names = new Array();
var f = document.forms['theForm'];
for (var n=0;n<3;n++)
names[n] =
f.elements['elem' + n].value.toUpperC ase();
f.elements['sorted'].value =
names.sort().jo in("+");
return false;

};

</script>

<form name='theForm' onsubmit='retur n SortNames();'>
<input name='elem0' value='xyz x'><br>
<input name='elem1' value='ABC x'><br>
<input name='elem2' value='Pqr x'><br>
<input type='' name='sorted' value=''><br>
<input type='submit' value='Sort me'><br>
</form>
============== =============== =============== =====

Are you sure I am not making your school assignment?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Sorry I did not give you the URL for the HTML page; it's
http://www.china-ready.com/jstest/arraysorting.htm Hope this makes
what I'm trying to do clearer.
Trying your page, IE shows javascript errors, that you can read and see
the line number. Debugging those errors is your first line of defence.
Actually, no I'm not doing a school assignment; this is entirely self-
imposed. I'm working my way thru Sams Teach Yourself Javascript in 24
Hours. This is the exercise at the end of Hour 5.
It seems you should try to understand the code, thoroughly bedore jumping
to the next. I never used a book for learning JS, as there is so much
code on the web that you can view source and try out.
If you have any suggestions about how to use Firebug to debug
Never heard of that, is that the standard FF debugger?
JavaScript; I'd appreciate your input. I'm so new that I can't figure
out the debug messages.
Debugging in the teaching fase should be done by hand, using small
snippets of code at a time [modular programming] that you test so tthat
you are absolutely sure it works as planned.

Put in alert(aVariable ); bedore and after the error line to inspect
errors and eliminate them one by one.

IE shows nice error warnings. FF too I am told.

[in IE you should switch "friendly errors" off, they are vey unfriendly
while debugging]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 17 '07 #4
pa************@ gmail.com wrote:
>
If you have any suggestions about how to use Firebug to debug
JavaScript; I'd appreciate your input. I'm so new that I can't figure
out the debug messages.
Just use the JavaScript console and you will see:

missing ; before statementsort.j s (line 8)
SortNames toUpperCase()(

The typo is pretty obvious once it has been pointed out!

--
Ian Collins.
Feb 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1472
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select one of three answers for each question, and automatically assign a value to their answer ("never"=0, "sometimes"=1, "always"=2). There would be anywhere from ten to thirty questions. I want the script to calculate the running total, and then...
2
8403
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
0
1897
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I have run into is that the emitted html at the end of the process is slightly different and doesn't work. Please don't be put off by all the source code. All the guts are in this first base class, and it doesn't do much. The rest is trivial...
1
1464
by: number1.email | last post by:
Hello, I have a simple Web Page Questionairre in which questions are read from a database, and the user can indicate the correct answer via either a radio input control or a dropdown list. The number of questions that is displayed on the screen can vary...depending on the number of questions that satisfy certain criteria. Does anyone have any sample code, or can show me how I can validate this Web Page in JavaScript so that the user is...
3
359
by: Shelly | last post by:
Hi, I really don't know javascript, though I can understand existing code. I know java, php, etc. Here is my question, and I assume it is simple. I have a page. On this page I have element_1 and element_2, among others. I have a button, which when clicked I want to go to: www.someotherpage.com?elem1=aaa&elem2=bbb where aaa is the value that is contained in element_1 and bbb is the value
6
2119
by: alex.kemsley | last post by:
Hi guys, I am trying to write a simple script in vain. I need it to first check to see if the cookie exists then if not write one with two variable var ref = document.referrer var page = location.href
4
1537
by: Brian Piotrowski | last post by:
Hi All, After many years of ASP 3.0, I am finally taking the plunge and moving to ASP.NET. I'm going through a few tutorials, and I'm wondering if someone can answer me a question on adding a simple Javascipt to an ASP.NET page. In my old ASP code, I used an #include function to add a javascript to my webpage. I've been reading that it is not recommended to use this technique in ASP.NET. The javascript I would like to add is pretty...
13
2044
by: aum | last post by:
Hi, I'm a Python programmer, just starting to get into javascript. On reading some of the js guides, and not liking any of the OO usage patterns I saw, I've cooked up something which python folks might find to taste. Here's the code - first the 'engine', then some code demonstrating the usage patterns. For me (and maybe for some of you), it promotes readability and some
7
1953
by: James Harris | last post by:
My Googling has let me down here - maybe because when it comes to Java I don't really know which type I need! If someone could point me in the right direction I'd appreciate it. My requirement is simple: to display a 2-d graph within a web page where the X and Y values are taken from a database (residing on the server hosting the web pages). The GUI is to allow panning forwards and backwards over time (the X values are 32-bit timestamps)...
5
1622
by: fussfart | last post by:
I'm trying to do something that should be very simple but isn't working! (I also want to do something somewhat more complicated, but that has to wait until I figure out the simple stuff.) First, I want to call out a .js file from inside a web page to write some stuff. I've done it before, but it's been a while. I've got it ultra-simplified just to try to get it to work. (Once I've got the bugs out, I'm going to put some real code in the .js...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.