0
<p>Today's Date: <?php echo $date; ?></p>
<p>Are you applying for a day, evening, or weekend class?</p>

<select name="date" id="wclass">
<option value="day">day</option>
<option value="evening">Evening</option>
<option value="weekend">Weekend</option>
</select>


Program Start Date:

<div id="dates"></div>

<script language="javascript">
$(document).ready(function() {

$("#wclass").change(function ()
{
    if( $("#wclass").val() == 'day' )
    {
        $('#dates').html('<select name="date">\
            <option value="date1"><?php echo $start1; ?></option>\
            <option value="date2"><?php echo $start2; ?></option>\
            <option value="date3"><?php echo $start3; ?></option>\
            <option value="date4"><?php echo $start4; ?></option>\
            <option value="date5"><?php echo $start5; ?></option>\
            <option value="date6"><?php echo $start6; ?></option>\
            <option value="date7"><?php echo $start7; ?></option>\
        </select>');
    } 
 }); 
});
</script>

So my issue is that i cant get the dates to come up, the list wont show. If i put the listi in on its own, works like a charm. There an issue with the javascript?

This is what the browser gets:

 $('#dates').html('<select name="date">\
 <option value="date1">Aug 11</option>\
 <option value="date2">May 5</option>\
 <option value="date3">June 6</option>\ 
 <option value="date4">January 7</option>\
 <option value="date5">April 5</option>\
 <option value="date6">December 3</option>\
   <option value="date7">October 15</option>\
 </select>'); 
Osman
  • 1,771
  • 4
  • 24
  • 47
  • 1
    Show us the actual markup generated. It's quite possible that the browser is bungling up the newlines in that multiline string literal you're trying to build. Clean workaround: http://stackoverflow.com/questions/805107/multiline-strings-in-javascript/805755#805755 – Matt Ball Aug 19 '11 at 19:44
  • The code comes from his previous question: http://stackoverflow.com/questions/7126039/display-php-using-javascript – Felix Kling Aug 19 '11 at 19:47
  • @Matt Ball -- My money is against that being the problem. I'm waiting to see the markup, but I'm betting on the $start variables contain HTML characters by accident. – Michael Lorton Aug 19 '11 at 19:49
  • they are html, they are html and they are dates. Are u asking to see the content of the variables? – Osman Aug 19 '11 at 19:55

2 Answers2

1

Since you are listening to the change event, your list will only show up if you select evening or weekend, and then change it back to day.

You can either force a change on initial load:

$("#wclass").change(function ()
{
    if( $("#wclass").val() == 'day' )
    {
        $('#dates').html('<select name="date">\
            <option value="date1"><?php echo $start1; ?></option>\
            <option value="date2"><?php echo $start2; ?></option>\
            <option value="date3"><?php echo $start3; ?></option>\
            <option value="date4"><?php echo $start4; ?></option>\
            <option value="date5"><?php echo $start5; ?></option>\
            <option value="date6"><?php echo $start6; ?></option>\
            <option value="date7"><?php echo $start7; ?></option>\
        </select>');
    } 
 }); 
}).val('day');

Or use then second solution I gave you here: Display php using javascript

Community
  • 1
  • 1
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • @user860869 You have an error in your syntax: `$(document).ready(function() { {`. That second `{` is extra, and is what's causing your Javascript error. – Joseph Silber Aug 19 '11 at 20:04
0

Your string concatenation is wrong. Try this

Working demo

$('#dates').html('<select name="date">'+
            '<option value="date1"><?php echo $start1; ?></option>'+
            '<option value="date2"><?php echo $start2; ?></option>'+
            '<option value="date3"><?php echo $start3; ?></option>'+
            '<option value="date4"><?php echo $start4; ?></option>'+
            '<option value="date5"><?php echo $start5; ?></option>'+
            '<option value="date6"><?php echo $start6; ?></option>'+
            '<option value="date7"><?php echo $start7; ?></option>'+
        '</select>');
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124