User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 423,717 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,154 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 6414 | Replies: 1
Reply
Join Date: Jun 2005
Posts: 2
Reputation: no1uknow is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
no1uknow no1uknow is offline Offline
Newbie Poster

calculating dynamic field names

  #1  
Jun 20th, 2005
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">
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Seattle, WA
Posts: 53
Reputation: senexom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
senexom's Avatar
senexom senexom is offline Offline
Junior Poster in Training

Re: calculating dynamic field names

  #2  
Jun 28th, 2005
You need to loop through a series of texboxes, right?

so something like this should work to get the value of your textboxes...

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)
   }
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 12:57 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC