Search code examples
javascriptformsexpressionenginehidden-fieldsafecracker

Form Hidden Field Substitution


I'm building a form using Expression Engine's Safecracker module.

One of the the required fields is the Title, which becomes the title of the EE channel entry.

What I'd like to do is set the Title field to be the combined first name and last name fields.

I started with this:

<form method="POST" action="#">

<input id="student_first_name" type="text" size="30" name="student_first_name"> 
<br>
<input id="student_last_name" type="text" size="30" name="student_last_name"> 
<br><br>
<input type="text" name="title" value=""/> 

</form>

And then added this:

$(function() {
    $('#student_first_name').keyup(function() {
        var snamef = $(this);
    });
    $('#student_last_name').keyup(function() {
        var snamel = $(this);
    });
    $("input[name='title']").val(snamel + " " + snamef);
    return false;
});​

​I can't get it to work, though: http://jsfiddle.net/tylonius/CY5zJ/4/

Am I missing a step (or just totally doing it wrong?)?

Also, am I possibly working too hard and Safecracker already has this function built in; similar to its live UrlTitle(); function?

Any help is appreciated.

Thanks,

ty


Solution

  • Better yet, avoid using javascript altogether and just use SafeCracker's dynamic_title parameter.

    dynamic_title="[student_first_name] [student_last_name]"