~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are probably missing an ending brace }. Try to pair the braces properly and you would be good to go.

And by the way, learn to format your code so that simple mistakes like these never occur or get a better text editor in case your current one doesn't support syntax highlighting.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Happy Diwali to all the members of Daniweb. Wishing you all a shining and prosperous year ahead. :)

Regards,
Sanjay.

thunderstorm98 commented: Thanks +2
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You sure are quick on the uptake. :icon_rolleyes:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There are some fundamental problems with your program structure. You seem to be doing password validation in 'Password.java' itself and that too in the main method which isn't such a good idea. Plus your 'Record.java' file is never used.

A simple way would be to create a new file 'Main.java' whose main method would create instances of the 'Password' and 'Record' type as per required by your program logic. Just make sure to keep nothing in main method except instance creation and method invocation i.e. maximum abstraction.

I would recommend you to read some good book and tutorials which teach Java as well as OO programming in general.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This example does exactly what you want. Also try to read a few links from this page if you plan on some serious stuff with possibly a good book by your side.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> If a God of Love created us, why do people die?
So that everyone sitting in heaven or hell gets a chance to crap on this brave new world. You don't plan on keeping all the fun to yourself, do you? ;P

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Ya..S.O.S what more we can do in life
Eat more food and drink more water. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Oh my, still eating food and drinking water.

joshSCH commented: TROLL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +12
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> What's the reason for assigning different classnames twice in sequence on the same object?
> Where do the variables link3 and link4 come from?
My program was just a literal translation of what the OP posted with the necessary syntactic changes made. I was expecting a bit more interaction from his side before dissecting the entire thing, but, meh. ;-P

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, since the confirm window is browser specific and not open to customizations. Your best bet would be to use some rich Javascript library like YUI (Yahoo! User Interface) to pop up custom alert and confirm boxes.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> However there's this one page that I changed with fontWeight that doesn't work.
Doesn't work is not a nice way to describe your problem. What exactly happens? Are there any javascript errors? Try opening the same page in Firefox and see if there is anything informative in the error console.

> anchor[i].getAttribute('name') IE doesn't like getAttribute() . Directly access the properties instead like anchor[i].name

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> But name is deprecated in XHTML. It won't even work, and the code won't validate.
The code I posted is valid XHTML.

> Read this portion of a page by W3C:
We don't need to read something we have well understood.

HTML 4 defined the name attribute for the elements a, applet, form, frame, iframe, img, and map. HTML 4 also introduced the id attribute. Both of these attributes are designed to be used as fragment identifiers.
[....]
Note that in XHTML 1.0, the name attribute of these elements is formally deprecated, and will be removed in a subsequent version of XHTML.

Anyways, I have had enough of trying to squeeze this simple concept in that brain of yours. If you still disagree with what we have posted, best of luck.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You certainly don't know what you are talking about.

> Use id instead of name.
OK, a bit of refresher. Form values are normally submitted using two methods: GET and POST. In GET, the form data is appended to the URL while in POST, the form data forms a part of the request payload. Despite all these differences, it is a fact that the form data is submitted in the form of 'name / value' pairs and not 'id / value' pairs.

Try this code:

<!-- nameOfThisFile.html -->

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>    
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>OK</title>
</head>
<body id="bodyMain">
    <form action="nameOfThisFile.html" method="GET">
        <div>
        <input type="text" id="txtId" value="OK" />
        <input type="text" name="txtName" value="txtName" />
        <input type="submit" value="Submit" />
        </div>
    </form>    
</body>
</html>

After pressing the submit button, take a look at the URL. Only the form field with the name attribute defined gets submitted.

Plus in case you were wondering, the document is a fully compliant XHTML strict document, which just proves my point that 'name' attribute is NOT deprecated inside form tag for form elements.

> I already asked the W3C this question.
...and misinterpreted their reply.

> The choice to use XHTML is not mine to make.
Wrong. The choice of DOCTYPE to be used definitely lies with the developer developing the web application.

> IE7 supports it fairly well.
"Fairly well" doesn't cut …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> document.link1.className = 'sel'; The way you are using to access the link element is incorrect. The document object doesn't have a property named 'link1', it has a link element having an id of 'link1'. The correct way of doing things would be:

var e = document.getElementById('link1');
e.className = 'sel';

A slightly better(definitely not the best!) way of doing it would be:

<script type="text/javascript">
function activate(link)
{
  var e = document.getElementById(link);
  var e3 = document.getElementById(link3);
  var e4 = document.getElementById(link4);

  if(!e || !e3 || !e4)
    return;
  if(link == 'link1')
  {
    e.className = 'sel';
    e.className = 'nav';
   }
   else if(link == 'link2')
   { 
     e.className = 'sel';
     e.className = 'nav';
   }
   
    e3.className = e4.className = 'nav';
}
</script>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Many people have already contributed a lot to this subject.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Are you using some sort of Javascript library? If yes, then you are better off asking this question in the respective forums since it might be more of a library issue.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You only/always free the memory which you explicitly allocated. If you dynamically allocate memory for a struct variable, you need to explicitly free it even though the members it contains follow the automatic memory allocation scheme.

If your struct contains instances of other structs which in turn are dynamically allocated, you must make sure that the cleanup routine walks the entire object graph and explicitly frees the allocated memory, starting from the lowest rung all the way up the object hierarchy.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> at url http://lowellbonnell.ca/index.php?view=Markets my ajax will only work if you insert the
> www in firefox. IE is fine either way.
This is because the browser thinks you are trying to do XSS.

iamthwee commented: *nods* +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The name attribute is now deprecated in the form tag.
'name' attribute is deprecated anywhere outside the 'form' tag. With the name attribute deprecated, how do you propose on accessing the form data server side?

>I must use XHTML.
It's interesting you would want to use something not supported by IE6 and IE7.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Javascript is case sensitive. And anyways there is no property input, it's 'value'. And the way you are accessing form elements is wrong.

Follow the links specified in this post and read them thoroughly.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Still food and water. Oh my!

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

First validate your document against your DOCTYPE here, do away with the issues which the validator spits out and then repost. I guess this is the second time I would be telling you that <html /> is incorrect. The validator ought to tell you a lot about your code.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, Moderators, Super Moderators, Admins and Donators can have custom titles.

PS: And oh Dani, how is it that you have a rep power of 31 by having 4 dots and I have 21 inspite of having 6 dots?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> There's nothing special in Java that doesn't exist in C++
Security as a language feature.

> A better model IMO is to use C++ and/or C for the raw engine and embed to or call
> from a very dynamic interpretted language
This approach has been used from times unknown. Letting C/C++ handle the rendering / physics while the developer can script away the entire game is the way to go. Graphics Engine / Physics engine / Particle engine come in as pluggable modules with a well exposed API. Look into games like 'Severance the Blade of Darkness or Freedom Force' which use Python as the scripting language.

> But not for the client end of a 3D FPS engine on PC/console with hot physics, graphics
> and the rest.
Agreed. Java has a long way to go.

>Why even try?
Because success comes to us only when we get used to failures.

> So to finish this off C/C++ or Java it does not really matter for most games.
It does matter. Every layer of abstraction has it's own price to pay. When we run C++ programs, what we run is raw machine code. When we run java programs, what we run is the JVM which loads the bytecode, converts it into machine code using JIT which is then executed.

>Unrelated; I actually prefer C# to Java,
Microsoft made a smart move by coming up …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> How are we supposed to know this "correct" way of doing things if most of the sources
> have not published it?
It's a real pity there are a lot of substandard tutorials / books out there to misguide beginners. Good sources are hard to find if one doesn't know what he is looking for.

> What is your source for this requirement of using the 'elements' nodelist?
DOM specification drafted by W3C.

> All of my sources say that it is becoming the obsolete way of addressing elements.
You are in bad company.

> What is the "correct" syntax for using a radio button?
Read this thoroughly for form access related queries. Then this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The prompt function returns a string. The switch construct and so also your calculations requires product be a numeric value. Convert the user input returned to a number before using it.

do
{
   product = Number(prompt("Enter something"));
   if(isNaN(product))
      product = -1;
   switch(product)
   {
      case 1: price = 1.0; break;
      /* and so on */
      default: price = 0;
   }
   total += price;
} while(product != 0);

Don't use document.write(). It's far from flexible. There are better ways of dynamically or programatically appending content to your document, known as DOM manipulation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That message is shown only when Javascript is executed locally and that too only on IE7. No such message would be displayed to the user once you site goes online, be rest assured.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> That syntax is necessary only if you are accessing the form using element numbers
Take a closer look at what I had posted. The fields or elements of a form should be accessed using the 'elements' nodelist or host object called HTMLCollection. Just because what you posted works now doesn't mean it always will.

> None of my books on JavaScript show it for an element address not using variables.
There are some things which you won't find in books. And anyways of the majority of books out there, only handful of them are worth reading.

> And it definitely does NOT work for addressing radio buttons
It certainly does. Please get your facts correct before putting a *NOT* there.

>Is the W3C now deprecating JavaScript usage too?
No, but you sure are using it the wrong way.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Accessing resources on the users computer doesn't mandate the use of absolute pathing. We can still use relative paths and at the same time access the images on the users computer provided the hierarchy / folder structure is well defined and considering the path / folder where our HTML resides as the root.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> water is harmful....
Yeah right, and food is toxic.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You people are getting confused between newline and carriage returns. A carriage return is just a carriage return and is always '\r'.

It's the 'newline' character which is different on different systems. (\r, \n, \r\n)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Instead of looping over the entire array to display it's contents, a clever way would be to convert it to a list and display it using it's toString() method (called implicitly). System.out.println(Arrays.asList(myArray));

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess that's the way Firefox by default displays the unordered list elements. Your best bet would be to use some other style for your unordered list elements. Something like:

ul
{
   list-style-type: circle;
}
/* or */
ul
{
   list-style-type: square;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A simple script to give you something to chew on:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function doChange(srcE, targetId)
{
    var val = srcE.options[srcE.selectedIndex].value;
    var targetE = document.getElementById(targetId);
    alert(val);
    removeAll(targetE);
    if(val == 'languages')
    {
        addOption('C++', targetE);
        addOption('Java', targetE);
        addOption('Scheme', targetE);
    }
    else if(val == 'tools')
    {
        addOption('Visual Studio', targetE);
        addOption('Netbeans', targetE);
        addOption('Eclipse', targetE);
    }
}

function addOption(value, e)
{
    var o = new Option(value);
    try
    {
        e.add(o);
    }
    catch(ee)
    {
        e.add(o, null);
    }
}

function removeAll(e)
{
    for(var i = 0, limit = e.options.length; i < limit - 1; ++i)
    {
        e.remove(1);
    }
}
</script>
</head>
<body>
<form action="#">
    <select name="selOne" id="selOne" onchange="doChange(this, 'selTwo')">
        <option value="default">---Select Something---</option>
        <option value="languages">Languages</option>
        <option value="tools">Tools</option>
    </select>
    <select name="selTwo" id="selTwo">
        <option value="default">---Select Something---</option>
    </select>
</form>
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

All browsers come with a built in XML parser which can be used to load XML files which can then be accessed using DOM. Read this for reading local XML files.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

>price = document.forms.nameOfForm.total_price.value;
Incorrect way of accessing form elements. Each form object has an 'elements' host object which has all the form elements as it's properties. Correct way would be: price = document.forms['nameOfForm'].elements['total_price'].value;

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That would be a lot of work for no real reason assuming that the intent of the OP is to build a working calculator and not learn stack operations.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can try out the Javascript focussed IDE called 'Aptana' or an online Javascript verifier called 'JSLint' to avoid silly mistakes and assistance with the general javascript syntax.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I would personally go for something along the lines of the below pasted code and make javascript do all the dirty work and keep the markup free of inline javascript:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd">
<html>
<head>
<title>Calculator</title>
<script type="text/javascript">
var inputString = '';
function init()
{
    var list = getElementsByClassName('calcBtn')[0].getElementsByTagName('*');
    for(var i = 0, limit = list.length; i < limit; ++i)
    {
        var elem = list[i];
        if(elem.type == 'button')
        {
            var str = elem.value;
            elem.onclick = function(e) {
                e = e || window.event;
                var el = e.srcElement || e.target;
                updateString(el);
            }
        }
    }
}

function getElementsByClassName(findClass)
{
    var result = [];
    var list = document.getElementsByTagName('*');
    for(var i = 0, list = list || [], limit = list.length; i < limit; ++i)
    {
        var e = list[i];
        if(e.className.indexOf(findClass) != -1)
        {
            result.push(e);
        }
    }
    return(result);
}

function updateString(elem)
{
    var value = elem.value.replace(/^\s|\s$/g, '')
    inputString += value;
    elem.form.elements['Input'].value = inputString;
}

function compute(frm)
{
    var element, result;
    try
    {
        element = frm.elements['Input'];
        result = eval(inputString);
        element.value = result || 'Empty Expression';
    }
    catch(e)
    {
        element.value = 'Invalid expression';
    }
    inputString = '';    //reset the string
}

function resetForm()
{
    inputString = '';
}
</script>
</head>

<body onload="init()";>
<form name="Calculator" action="#" onreset = "resetForm();"/>
<input type="text" name="Input" /><br />
<div class="calcBtn">
    <input type="button" name="plus" value=" + " />
    <input type="button" name="minus" value=" - " />
    <input type="button" name="times" value=" * " />
    <input type="button" name="div" value=" / " />
    <input type="button" name="mod" value=" mod " …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Some points:

  • Why are you treating head and body tags as having a empty content model by writing them as <head /> and <body />? It's incorrect.
  • You are having one too many double quotes in your onclick handlers. onclick="updateString"('+')" should be onclick="updateString('+')"
  • Placing alert's all over your code or using debugger like 'Firebug' if you are developing for Firefox is a good way to spot such errors.
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use the replace function or the href property of the location object to do the same.

if (document.input.password.value == p + a + s + e)
{
    /* assuming the the file resides on the same path */
    location.replace('gmtv.html'); 
    /* or use location.href = 'gmtv.html' */
}
else
{
    alert("incorrect");
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Is .NETs CLI/CLR the same idea?
Since I am not involved with C# in any way, I would be in no position to answer that question but it seems that C# code is compiled to an intermediate byte code called IL which is converted on the fly into machine code.

Asking the same question in the C# forums would be more yieldy.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Water.

The taste of two hydrogen atoms mingling with an oxygen atom is unbeatable.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The Java specification doesn't mandate the JVM to be written in any particular language, but yes, it's almost always written in C like other VM's out there.

But you have got to realize that Java is an interpreted and not a compiled langauge. The java code is compiled by the 'javac' tool into a class file which is then loaded by the 'java' interpreter which interprets the bytecode and executes the given program. There is on the fly conversion from the java byte code(which is machine code to the java machine) to machine specific code.

At present, there is very slick chance of interpreted languages beating the performance offered by languages which are directly compiled to platform specific machine code like C and C++.

A rule of thumb: You don't gain abstractions for free.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A simple google search gave a lot of results. Be sure to try a few of them and if you still don't get it, post a problems.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No, javascript on the client machine can't and is not made to read files on the server. It's a client side language though it can be very well used on your server (that would be something rare).

To pass values from your server variables to javascript, you would need to dynamically generate the javascript content. In Java, we can do something like this:

/* Greet.jsp */

<html>
<head>
  <script>
  /* Here I am fetching the user name from the session variable which
   * I set on the server. There has to be a similar API offered by Perl for
   * accessing server side variables. Since only plain HTML pages are served
   * to the client / user by the server after processing the server side
   * constructs, you get to see the value of the username assigned to 
   * the javascript variable.
   */
  myName = '<%= session.getAttribute("username") %>';
  
  function greet() { alert('Hello ' + myName); }
  </script>
</head>
<body>
  <input type="button" value="Click" onclick="greet();" />
</body>
</html>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can't. It's implementation defined. Each browser has it's own way of showing the alert box though the presence of 'external skins' installed for that browser may change the appearance of the alert box but other than that, you have no control whatsoever.

Your best bet would be to use a Javascript library like YUI which pops up a programmable and skinnable "div" giving you the impression of a custom alert box.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

*sigh*

Still eating food and drinking water.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The search results provided by Google were pretty helpful...