[jQuery] Inserting fields dependant upon select
Posted: Thu Apr 05, 2007 12:35 pm
I'm trying to use jQuery to insert some fields when the user selects a certain item from a <select> menu. I'm using php to render the html into the html() function. Is there a better way to do this? This one only has one field, but the other selections may have up to 10 or more
event/recurring/daily.tpl.php
(this has to be all placed on one line so I don't get an "Undetermined string literal" error
EDIT: One thing I do like about this solution is that it allows me to reuse the daily.tpl.php file for the users who DO NOT have javascript enabled (I'll show this part of the form to users after the submit the first form)
Code: Select all
/**
* This removes the need for a multi-page form by using javascript
* to select the appropriate fields
*/
$('#event_recurring_type').change(function(){
var recurring_type = $(this).attr('value');
switch (recurring_type)
{
case 'daily':
/* remember not to use double quotes (escape them) in templates or it will screw up the javascript */
$('#recurring_type_selection')
.hide()
.html('<?php echo $this->render('event/recurring/daily.tpl.php'); ?>')
.fadeIn('fast');
break;
}
});(this has to be all placed on one line so I don't get an "Undetermined string literal" error
Code: Select all
<fieldset> <legend>Daily Recurrence</legend> <div><label for="every">Every:</label> <input type="text" name="every" id="every" class="text" value="" /></div></fieldset>