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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Eval function assignment

    Hi All,

    This is my function

    function outputSelected() {

    alert(window.opener.document.forms[0].txt11_19.value);
    alert(window.opener.document.forms[0].rdo11.length);

    var questionID = document.forms[0].cntQuestion.value;
    var choiceID = document.forms[0].cntChoice.value;
    var txtValue = document.forms[0].strEmpNo.value + " " + document.forms[0].strName.value;
    alert(txtValue);
    var leftValue = 'window.opener.document.forms[0].txt' + questionID + '_' + choiceID + '.value =' + txtValue;
    eval(leftValue);
    }

    all the alerts work as expected. bu the eval function does not.
    error: expected ';'

    any ideas what is happening. or is there any other way of doing this.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Can I rewrite that, please?
    Code:
    function outputSelected() 
    {
        var form = window.opener.document.forms[0];
        alert( form.txt11_19.value );
        alert( form.rdo11.length);
    
        var questionID = form.cntQuestion.value;
        var choiceID = form.cntChoice.value;
        var txtValue = form.strEmpNo.value + " " + form.strName.value;
        alert(txtValue);
        form.elements["txt" + questionID + "_" + choiceID].value = txtValue;
    }
    FWIW, the error in your original is that when you do the eval you need quotes around the value being assigned, since it is clearly *NOT* a number.
    Code:
    var leftValue = 'window.opener.document.forms[0].txt' + questionID + '_' + choiceID + '.value = "' + txtValue + '"';
    But isn't my way easier to read and understand?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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