| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | |
| |
| | #2 (permalink) |
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Hi, Can you elaborate a bit more please? You have the select there so I'm guessing you want to take the value of that and use it in a calculation but without more information I can't really provide much help. As a tip, you can give the select an id and use it like this: Code: select = document.getElementById('selectid');
document.write(100 - select.value); |
| |
| | THREAD STARTER #3 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Sorry, I was a bit rushed. Basically, I want to add the values of 5 dropdown boxes: dd[0], dd[1], dd[2], etc. and then display the calculated value in a div using innerHTML.
__________________ Encenta - Amazon Associates CMS |
| |
| | #4 (permalink) |
| NamePros Member Join Date: Sep 2005
Posts: 160
![]() | Code: <script language="javascript">
//GLOBAL Var.
var maxIndex= 5; //Put the # of form fields (takes in mind it starts numbering with the 0)
///////////////////////////////////////
function Sumatory (f, numFields) {
///////////////////////////////////////
var sumatory= 0;
for (k=0; k < numFields; k++) {
theValue= f.dd[k].value;
if (!(isNaN(theValue))) {
sumatory+= parseInt(theValue);
}
}
//return (sumatory);
document.getElementById('visor').innerHTML= sumatory;
}
</script> ????: NamePros.com http://www.namepros.com/showthread.php?t=362229 Code: <div id="visor"></div> Add a button in your form, something like this: Code: <input type="button" value="Add values" onClick="Sumatory (this.form, maxIndex)"> I personally would use Prototype library (www.prototypejs.org) to access DOM elements in a much powerful way. Once you use it, you'll love it. Couldn't test the code, so I hope not to have made a syntax error or something like that. Regards.
Last edited by guillermobt; 08-16-2007 at 12:45 PM.
Reason: add a parseInt!
|
| |