Web Analytics Made Easy -
StatCounter Update feilds in list by field.value ++ (+1)?? - CodingForum

Announcement

Collapse
No announcement yet.

Update feilds in list by field.value ++ (+1)??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Update feilds in list by field.value ++ (+1)??

    I'm having a heck of a time getting this script to work.

    I have a "contacts list" dynamically generated from MySQL db via php, which incldes a text field named contact_cycle.
    The number of rows returned may be as many as 100, and the contact_cycle.value will vary from row to row.

    I'm trying to establish a script that (upon clicking a mass_update button) will add "1" to the value of each contact_cycle field, for all records where a corrisponding checkbox (name= "mass[]") is checked.

    The following is a pared-down version of the list by which to test/develop script. Am I barking up the wrong tree here????

    <script type="text/javascript">
    var contact_cycle = document.getElementsByName("contact_cycle");
    var add_one = document.getElementsByName("add_one");
    var T1 = document.getElementsByName("T1");
    function update_cycle(){
    ////var test alerts do work ///////
    //if (add_one.value !==""){alert("hooray!");}
    //if (contact_cycle.value !==""){alert("hooray!");}
    /// TEST T1.value doesn not work???///////
    //T1.value = add_one.value;}
    Number(add_one.value) == Number(contact_cycle.value)+1;
    }
    </script>

    <table>
    <tr>
    <td scope="col"><input type='checkbox' name='massall' value=''
    onclick='checkAll(document.MassUpdate, "mass[]", this.checked)'></td>
    <td scope="col"><slot>Cycle&nbsp;</slot></td>
    </tr>
    <tr>
    <td><input type='checkbox' name='mass[]'></td>
    <td><input type="text" name="contact_cycle" size="1" value="5"></td>
    </tr>
    <tr>
    <td><input type='checkbox'name='mass[]'></td>
    <td><input type="text" name="contact_cycle" size="1" value="2"></td>
    </tr>
    </table>
    <br>
    <input type='button' name='Update' value='Cycle' onclick="update_cycle()">
    Cycle
    <input type="text" size="1" id="mass_cycle" name="add_one" value="0">
    TEST
    <input type="text" size="1" name="T1" value="0">

  • #2
    Okay, I have added <form listView></form> (which doesn't seem to break the php/crm) and switched from
    var contact_cycle = document.getElementsByName("contact_cycle");
    to use
    var contact_cycle = document.listView.contact_cycle;

    <script type="text/javascript">
    function update_cycle(){

    var contact_cycle = document.listView.contact_cycle;
    var add_one = document.listView.add_one;
    add_one.value = Number(contact_cycle.value)+1;
    }
    </script>

    <table>
    <form name="listView">
    <tr>
    <td scope="col"><input type='checkbox' name='massall' value='' onclick='checkAll(document.MassUpdate, "mass[]", this.checked)'></td>
    <td scope="col"><slot>Cycle&nbsp;</slot></td>
    </tr>
    <tr>
    <td><input type='checkbox' name='mass[]'></td>
    <td><input type="text" name="contact_cycle" size="1" value="5"></td>
    </tr>
    </table>
    <br>
    <input type='button' name='Update' value='Cycle' onclick="update_cycle()">
    Cycle
    <input type="hidden" size="1" id="mass_cycle" name="add_one">
    </form>
    Now the script works, but only with one return in the "list".

    Is it possible to loop this somehow to run through each <input name=contact_cycle>???

    Comment

    Working...
    X