简体   繁体   中英

Prefill a HTML value with a variable?

How could I make a HTML input field value prefilled with a variable? In this case, the modal-body variable. I read about using document.write but how could we use this with a variable?

We're using Mandrill & Full Calendar.
Many, many thanks!

CODE:

 {
title: 'Event',
start: '2016-03-26T11:00:00',
end: '2016-03-26T12:00:00',
},
    ],
     eventClick: function(event) {
  console.log(event)
    // alert(event.start.format('MMMM Do YYYY'))
  var start = event.start.format('MMMM Do YYYY'),
    end = event.end.format('MMMM Do YYYY'),
    html = '<p>Starts: ' + start + '<p>';
  html += '<p>Ends: ' + end + '<p>';
  var modal = $("#modal");
  modal.find(".modal-title").html(event.title);
  modal.find('.modal-body').html(html)
  modal.modal();
    }
});
});
});//]]>

          </script>
        <script type="text/javascript"> 

          $(document).ready(function() {
// Generate a simple captcha
function randomNumber(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
}

function generateCaptcha() {
    $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
}

generateCaptcha();

$('#contactForm')
.formValidation({

})
.on('success.form.fv', function(e) {
    // Prevent default form submission
    e.preventDefault();

    // Change these values to match with your application
    var MANDRILL_API_KEY = 'YOUR-MANDRILL-API-KEY',
        EMAIL_SUBJECT    = 'Find Volunteerships - Sign Up Confirmation ',


    var $form = $(e.target),
        // Generate a message based on submitted form data
        body  = [
            '<strong>Name:</strong> ' +     $form.find('[name="firstName"]').val() + ' ' + $form.find('[name="lastName"]').val(),
            '<strong>School</strong> ' + ($form.find('[name="school"]').val() || 'n/a'),
            '',
            '<strong>Message:</strong> ',
            $form.find('[name="school"]').val()
        ].join('<br/>');

    // Send the message
    $.ajax({
        type: 'POST',
        url: 'http://mandrillapp.com/api/1.0/messages/send.json',
        contentType: 'text/plain',
        dataType: 'json',
        data: {
            key: MANDRILL_API_KEY,
            message: {
                from_name: $form.find('[name="fullName"]').val(),
                from_email: $form.find('[name="email"]').val(),
                to: [
                    {
                        email: $form.find('[name="email"]').val(),
                       name: $form.find('[name="fullName"]').val(),
                        'type': 'to'
                    }
                ],
                auto_text: true,
                subject: EMAIL_SUBJECT,
                html: body
            }
        }
    }).done(function(response) {
        // Clear the form
        $form.formValidation('resetForm', true);

// Regenerate the captcha

.on('err.form.fv', function(e) {
        // Regenerate the captcha
        generateCaptcha();
    });

        // Show the message
        response.status === 'error'
            ? $('#alertContainer')
                .removeClass('alert-success')
                .addClass('alert-warning')
                .html('Sorry, cannot register the sign up')
                .show()
            : $('#alertContainer')
                .removeClass('alert-warning')
                .addClass('alert-success')
                .html('Your sign up has been successfully registered')
                .show();
    }).fail(function(jqXHR, textStatus, errorThrown) {
        $('#alertContainer')
            .removeClass('alert-success')
            .addClass('alert-warning')
            .html('Sorry, cannot register the sign up')
            .show();
    });

Not sure what you meant, probably something like this?

modal.find('.' + modal-body)

But variable cant have name with "-" sign in it..

" modal-body " is equal to " modal - body ", so it will minus one from the other..

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