简体   繁体   中英

Adding php Session data inside javascript function

This is my function on inserting a given piece of text into a text field, If the user leaves it blank. I'm unsure of how to replace: "userid 46" with: "userid <?= $_SESSION["user"]["id"] ?>" Here is my function script.

function InsertDefaultValues()
{
    // Leave this line as is. Customization follows.
    var FieldsAndDefault = new Array();
    // Customization:
    // For each field that will have custom information is 
    //   submitted blank, use this format:
    //     FieldsAndDefault.push("FieldIDvalue Default value");

    FieldsAndDefault.push("userid 46");

    // End of customization.
    ///////////////////////////////////////
    for( var i=0; i<FieldsAndDefault.length; i++ )
    {
        FieldsAndDefault[i] = FieldsAndDefault[i].replace(/^\s*/,"");
        var pieces = FieldsAndDefault[i].split(" ");
        var field = pieces.shift();
        var f = document.getElementById(field);
        if( f.value.length < 1 ) { f.value = pieces.join(" "); }
    }
    return true;
}

您差一点就拥有了。

FieldsAndDefault.push("userid <?php echo $_SESSION['user']['id']; ?>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM