944,179 Members | Top Members by Rank

Ad:
Jun 20th, 2005
0

calculating dynamic field names

Expand Post »
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">
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
no1uknow is offline Offline
2 posts
since Jun 2005
Jun 28th, 2005
0

Re: calculating dynamic field names

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)
  1. for(i=0; i<document.forms[0].elements.length; i++){
  2. if(document.forms[0].elements[i].type == 'text')
  3. var elName = document.forms[0].elements[i].name;
  4. var elValue = document.forms[0].elements[i].value;
  5. // Display element name and value
  6. alert(elName +' = '+ elValue)
  7. }
  8. }
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
senexom is offline Offline
54 posts
since Jun 2005
Sep 7th, 2009
0

Re: calculating dynamic field names

Click to Expand / Collapse  Quote originally posted by senexom ...
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)
  1. for(i=0; i<document.forms[0].elements.length; i++){
  2. if(document.forms[0].elements[i].type == 'text')
  3. var elName = document.forms[0].elements[i].name;
  4. var elValue = document.forms[0].elements[i].value;
  5. // Display element name and value
  6. alert(elName +' = '+ elValue)
  7. }
  8. }
Hi, thanx for this solution it's near to fix my same problem too...

I have this (php dynamic fields):
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
accountholder is offline Offline
20 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Detecting Mozilla using JavaScript
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript event stuff





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC