| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| SQLdumpster.com | Hi, I'm looking for a way to calculate a set of dropdown lists. Eg: HTML Code: <select name="dd[0]"> <option value="+21">Value</option> <option value="-21">Value</option> </select> Thanks
__________________ !!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!! Free Databases for your Website | All Things Playstation 3 Website Design Books | Music While You Work? | Computer Gadgets |
| |
| | #2 (permalink) |
| Stud Sausage | 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);
|
| |
| | #3 (permalink) |
| SQLdumpster.com | 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.
__________________ !!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!! Free Databases for your Website | All Things Playstation 3 Website Design Books | Music While You Work? | Computer Gadgets |
| |
| | #4 (permalink) |
| NamePros Member | 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>
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.
__________________ technfo.com - pick.pk - ajaxpro.es - gbt.es - jamones.cn - sqzd.com - geoinfo.net Free URL Redirection (for sale) (62,000+ subdomains and growing!!) Real IP / Proxy IP Last edited by guillermobt; 08-16-2007 at 11:45 AM. Reason: add a parseInt! |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |