M
Mechphisto
Hi.
I've a page where I'm trying to add together all the numeric values of
a set of select boxes, but I can't get the javascript to add the
numbers as numbers instead of concatenating as strings.
Here's my script:
<script type="text/javascript">
function valSel() {
var selCount=0;
var selV1=document.getElementById('list_primaryinfo_1').value;
var selV2=document.getElementById('list_primaryinfo_2').value;
var selV3=document.getElementById('list_primaryinfo_3').value;
var selV4=document.getElementById('list_primaryinfo_4').value;
var selV5=document.getElementById('list_primaryinfo_5').value;
selCount = (selCount + selV1);
selCount = (selCount + selV2);
selCount = (selCount + selV3);
selCount = (selCount + selV4);
selCount = (selCount + selV5);
selCount = (selCount +
document.getElementById('list_primaryinfo_6').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_7').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_8').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_9').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_10').value);
if (selCount != 55) {
alert(selCount);
return false ;
}
}
</script>
(You see I tried to process half of them as vars first just to see if
that'd change anything -- it's didn't.)
And here's a sample of the the select fields:
<select name="list_receive_info-su_meetings" size="1"
id="list_primaryinfo_1">
<option value="0" selected="selected">--</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
Service unit meetings<br />
<select name="list_receive_info-web_site" size="1"
id="list_primaryinfo_2">
<option value="0" selected="selected">--</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
(I also tried it without the quotes surrounding the values, like this:
<option value=0 selected="selected">--</option>
<option value=10>10</option>
<option value=9>9</option>
but no difference.)
Any ideas what I can do about this?
Thanks!
Liam
I've a page where I'm trying to add together all the numeric values of
a set of select boxes, but I can't get the javascript to add the
numbers as numbers instead of concatenating as strings.
Here's my script:
<script type="text/javascript">
function valSel() {
var selCount=0;
var selV1=document.getElementById('list_primaryinfo_1').value;
var selV2=document.getElementById('list_primaryinfo_2').value;
var selV3=document.getElementById('list_primaryinfo_3').value;
var selV4=document.getElementById('list_primaryinfo_4').value;
var selV5=document.getElementById('list_primaryinfo_5').value;
selCount = (selCount + selV1);
selCount = (selCount + selV2);
selCount = (selCount + selV3);
selCount = (selCount + selV4);
selCount = (selCount + selV5);
selCount = (selCount +
document.getElementById('list_primaryinfo_6').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_7').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_8').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_9').value);
selCount = (selCount +
document.getElementById('list_primaryinfo_10').value);
if (selCount != 55) {
alert(selCount);
return false ;
}
}
</script>
(You see I tried to process half of them as vars first just to see if
that'd change anything -- it's didn't.)
And here's a sample of the the select fields:
<select name="list_receive_info-su_meetings" size="1"
id="list_primaryinfo_1">
<option value="0" selected="selected">--</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
Service unit meetings<br />
<select name="list_receive_info-web_site" size="1"
id="list_primaryinfo_2">
<option value="0" selected="selected">--</option>
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
(I also tried it without the quotes surrounding the values, like this:
<option value=0 selected="selected">--</option>
<option value=10>10</option>
<option value=9>9</option>
but no difference.)
Any ideas what I can do about this?
Thanks!
Liam