| | |
calculating dynamic field names
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2005
Posts: 2
Reputation:
Solved Threads: 0
I have several fields being updated for a parking structure... The client inputs the number of cars and can immediately see the percentage before updating the database....
The field names always change so I need the JavaScript to be able to pick up the unique field names calculate and place into the total field box...
I found this code online, but I need to do this dynamically for hundreds of lots...
So basically I have a field name and an ID number identifying the 3 related fields...
Here's an example that works for one lot:
<HEAD>
<script type="text/javascript">
<!-- Begin
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.autoSumForm.firstBox.value;
two = document.autoSumForm.secondBox.value;
document.autoSumForm.thirdBox.value = (one * 1) / (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
// End -->
</script>
</HEAD>
<BODY>
<form name="autoSumForm">
<input type=text name="firstBox" value="1000" onFocus="startCalc();" onBlur="stopCalc();"> /
<input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();"> =
<input type=text name="thirdBox">
</BODY>
Here is an example of what I need, notice there is an ID number after each field name....
<input type=text name="firstBox123" value="1000" onFocus="startCalc();" onBlur="stopCalc();"> /
<input type=text name="secondBox123" value="" onFocus="startCalc();" onBlur="stopCalc();"> =
<input type=text name="thirdBox123">
<input type=text name="firstBox221" value="1000" onFocus="startCalc();" onBlur="stopCalc();"> /
<input type=text name="secondBox221" value="" onFocus="startCalc();" onBlur="stopCalc();"> =
<input type=text name="thirdBox221">
The field names always change so I need the JavaScript to be able to pick up the unique field names calculate and place into the total field box...
I found this code online, but I need to do this dynamically for hundreds of lots...
So basically I have a field name and an ID number identifying the 3 related fields...
Here's an example that works for one lot:
<HEAD>
<script type="text/javascript">
<!-- Begin
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.autoSumForm.firstBox.value;
two = document.autoSumForm.secondBox.value;
document.autoSumForm.thirdBox.value = (one * 1) / (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
// End -->
</script>
</HEAD>
<BODY>
<form name="autoSumForm">
<input type=text name="firstBox" value="1000" onFocus="startCalc();" onBlur="stopCalc();"> /
<input type=text name="secondBox" value="" onFocus="startCalc();" onBlur="stopCalc();"> =
<input type=text name="thirdBox">
</BODY>
Here is an example of what I need, notice there is an ID number after each field name....
<input type=text name="firstBox123" value="1000" onFocus="startCalc();" onBlur="stopCalc();"> /
<input type=text name="secondBox123" value="" onFocus="startCalc();" onBlur="stopCalc();"> =
<input type=text name="thirdBox123">
<input type=text name="firstBox221" value="1000" onFocus="startCalc();" onBlur="stopCalc();"> /
<input type=text name="secondBox221" value="" onFocus="startCalc();" onBlur="stopCalc();"> =
<input type=text name="thirdBox221">
You need to loop through a series of texboxes, right?
so something like this should work to get the value of your textboxes...
so something like this should work to get the value of your textboxes...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
for(i=0; i<document.forms[0].elements.length; i++){ if(document.forms[0].elements[i].type == 'text') var elName = document.forms[0].elements[i].name; var elValue = document.forms[0].elements[i].value; // Display element name and value alert(elName +' = '+ elValue) } }
•
•
Join Date: Sep 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
You need to loop through a series of texboxes, right?
so something like this should work to get the value of your textboxes...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
for(i=0; i<document.forms[0].elements.length; i++){ if(document.forms[0].elements[i].type == 'text') var elName = document.forms[0].elements[i].name; var elValue = document.forms[0].elements[i].value; // Display element name and value alert(elName +' = '+ elValue) } }
I have this (php dynamic fields):
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<input name="itemID[]" value="<?=$row[id]?>" /><input name="price[]" value="<?=$row[price]?>" /><input name="qty[]" value="" onFocus="startCalc();" onBlur="stopCalc();" /><input name="subtotal[]" value="" />
Last edited by accountholder; Sep 7th, 2009 at 2:58 am.
![]() |
Similar Threads
- Don't display an empty form field? (PHP)
- Please I need help formatting an output file and sorting the names! (C++)
- Urgent.....Dynamic Changes.... (JavaScript / DHTML / AJAX)
- IIS connection will not write data (ASP)
- sort on field names; refresh page? (PHP)
- linking issues (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Detecting Mozilla using JavaScript
- Next Thread: Javascript event stuff
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box bug calendar cart codes column cookies createrange() css cursor date debugger decimal design dom download dropdown element embed enter error events firefox focus form frameworks getselection google gwt hiddenvalue hint html htmlform ie7 iframe image() images index java javascript javascripthelp2020 jawascriptruntimeerror jquery jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 onerror onmouseover paypal php player position post problem programming progressbar prototype rating redirect regex runtime safari scale scriptlets search security select software sql starrating text textarea toggle unicode validation variables w3c webservice website window windowofwords windowsxp xml





