JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 26th, 2001, 09:23 AM
underwarez underwarez is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: toronto, ontario, canada
Posts: 10 underwarez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
javascript functions

I have a form which is organized with a table, each row of the table has several form elements (at least 3 text fields each)

<form>
<tr>
<input type=text name="q1">
<input type=text name="q1_value">
<input type=text name="q1_total">
</tr>
<tr>
<input type=text name="q2">
<input type=text name="q2_value">
<select option ... name="q2_dazy">
<input type=text name="q2_total">
</tr>

...
<tr>
<input type=text name="q30">
<input type=text name="q30_value">
<select size=1 ... name="q30_dazy">
<select size=1 ... name="q30_lazy">
<input type=text name="q30_total">

</tr>...
<form>

Now I'm writing a javascript function, that'll fill in *_total based on *_value and a constant. i.e. q3_total = q3_value * 50;

My problem is that my way is really long, I have a lot of if statements to do it. Is there a better way?

my way:
function(name)
if (name == q1)
q1_total = q1_value * 50;
...
if (name == q30)
q30_total = q30_value * 50;






9

Reply With Quote
  #2  
Old October 29th, 2001, 03:51 PM
Alexandr Alexandr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Belarus
Posts: 30 Alexandr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
hi, underwarez

I think you should do it like this

function getTotal(name)
{
eval("document.mainForm." + name + "_total.value = document.mainForm." + name + "_value.value * 50");
}


and html code for proper working

<form name="mainForm">
<tr>
<input type=text name="q1">
<input type=text name="q1_value">
<input type ....

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > javascript functions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap