Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    160
    Thanks
    40
    Thanked 0 Times in 0 Posts

    Value from script won't POST

    Hi All,

    I have the following script:

    <script type="text/javascript">
    function assignMe() {
    var creator = document.getElementById('EnteredBy').value;
    var assignee = document.getElementById('AssignTo').value;
    var chkAssign = document.getElementById('assignSelf');
    if (chkAssign.checked) {
    assignee = creator;
    }else{
    assignee = "";
    }
    alert (assignee);
    }
    </script>


    The script is called on the onclick event of 'assignSelf' checkbox. If the box is checked it copies the value of 'EnteredBy' to 'AssignTo', otherwise it clears the value of 'AssignTo'. The alert() is there for testing and it is showing that the vakue is being copied and cleared properly.

    My problem is for some reason the value of 'AssignTo' doesn't appear to be posting. When I check the database, the value is empty for that field.

    I will be happy to post more code if needed. Thanks in advance for any help.

    Ken

    UPDATE:

    Got it working. Here is the corrected script:

    <script type="text/javascript">
    function assignMe() {
    var creator = document.getElementById('EnteredBy').value;
    var assignee = document.getElementById('AssignTo');
    var chkAssign = document.getElementById('assignSelf');
    if (chkAssign.checked) {
    assignee.value = creator;
    }else{
    assignee.value = "";
    }
    }
    </script>
    I had to take the .value off of the var declaration for ' AssignTo' and move it to the if statement.
    Last edited by MaDmiX; 08-10-2013 at 09:16 PM. Reason: Got it fixed

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    If the field names are the same as the IDs you are using, the code can be simplified like this. If not the same, just change them accordingly.
    Code:
    document.getElementById('assignSelf').onclick = function(e) {
        if (this.checked) {
            this.form.AssignTo.value = this.form.EnteredBy.value;
        }
    }

  • #3
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    160
    Thanks
    40
    Thanked 0 Times in 0 Posts
    Hi glenngv,

    That is more concise. Thanks!

    Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •