1

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;
}
0

1 Answer 1

1

you nearly had it.

FieldsAndDefault.push("userid <?php echo $_SESSION['user']['id']; ?>");
Sign up to request clarification or add additional context in comments.

2 Comments

<?= is a shortcut for <?php echo in any case, though not always available if short_tags was off in <5.4.0
Yes I know this. I was trying to keep the answer as clear and as simple as possible so someone without a more advanced understanding could see the basic structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.