1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    toronto, ontario, canada
    Rep Power

    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)

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

    <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">


    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:
    if (name == q1)
    q1_total = q1_value * 50;
    if (name == q30)
    q30_total = q30_value * 50;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Rep Power
    function evalValue( name ) {
    var strEval = name + "_total = " + name + "_value * 50;";
    eval( strEval );

    N24 - ALL the newspapers on ONE site.
    JMailbox - Free Web Based Email Client.

IMN logo majestic logo threadwatch logo seochat tools logo