Hi guys for my first piece of work on javascript i have to check a few html form questions which is provided. But im pretty clueless on how to do it, or even start it. First of all how would i check like a drop down menu had the right chosen value? or how would i count the correct answers ? Sorry just want some idea on how to get started with javascript.

Recommended Answers

It would help to know what you are planning to do with the data you collect from the user. Can you explain?

Jump to Post

m not understanding ur problem...wht exactly you are trying to do....like how you want to use drop down.can you send me the
small example of it so that i can better understand it...
but one thing i know is to count the correct answers by using function...
here it is.

Jump to Post

All 5 Replies

What I'm basically asking is how would i mark it? would i store the answers in an array or something?

It would help to know what you are planning to do with the data you collect from the user. Can you explain?

m not understanding ur problem...wht exactly you are trying to do....like how you want to use drop down.can you send me the
small example of it so that i can better understand it...
but one thing i know is to count the correct answers by using function...
here it is.

Array.prototype.count = function() {
    return this.length;
};

hope it works...

Hi sorry i was totally confused initially on this. Done a bit of research into it now. Basically we have an html form as sort of a test. Then we have to check it with Javascript and then on the server side use php (i'm just doing the javascript for now).

someone said they used this 'forms[0].username' which confused me because i dont know what that would be used for.

Im confused about a lot of it, but even the basics escape me. For instance ;

<p id="Q1"> What's the Swedish Capital?
<br />
<select name="Q1">
<option value="">Choose one from the following:</option>
<option value="a">Paris</option>
<option value="b">Stockholm</option>
<option value="c">Copenhagen</option>
<option value="d">Oslo</option>
</select>
How in javascript can i check the result given? is it something to do with getElementByID? if someone could provide me with the javascipt for this it would be a big help, i basically just want to undestand the syntax to get me started. Is it like (as a function) if (stockholm == Q1)
return true;

So you would need to do something like this:

function validate_form () {
    valid = true;
    if ( document.FORMNAME.Q1.value != "stockholm" ) {
        alert ( "Please fill in the 'Your Name' box." );
        valid = false;
    }
    return valid;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.