Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting values?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How to get values of for instance a checkbox with 3 checkboxes, how to make the function that decidedes if they are checked or not? Is it it possible to do this:

var lunsj=document.bestilling.lunsj.checked
function _lunsj(form) {
if (document.bestilling.lunsj.checked)
lunsj=parseInt(document.bestilling.lunsj.value);
else
lunsj=0

And the same with select-boxes, can u do like this:

var rompris=document.bestilling.rom.value
function _rompris(form)
{
if (form.Rom.options[0].selected)
rompris=300
else if (form.Rom.options[1].selected)
rompris=320
else if (form.Rom.options[2].selected)
rompris=400
else (form.Rom.options[3].selected)
rompris=700
}

And if this is possible; how do yo do the summary in the end?


thanX
 
Well you can also loop thru them to decide which ones are checke this way you can have as many as you want, without having to make a new if branch for each. You can ask for an elements type when you do this:

for(var i=0;i<document.form.elements.length;i++){

if(document.form.elments.type==&quot;checkbox&quot;){
if(document.form.elments.checked){
// do stuff
}
}
else if(document.form.elments.type==&quot;textbox&quot;){
// Do textbox stuff.
}

}

With the checkboxes - you could keep an array which you can store the indices of the one which have been checked
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top