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>'); 
4
  • 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: stackoverflow.com/questions/805107/… Commented Aug 19, 2011 at 19:44
  • The code comes from his previous question: stackoverflow.com/questions/7126039/… Commented Aug 19, 2011 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. Commented Aug 19, 2011 at 19:49
  • they are html, they are html and they are dates. Are u asking to see the content of the variables? Commented Aug 19, 2011 at 19:55

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

@user860869 You have an error in your syntax: $(document).ready(function() { {. That second { is extra, and is what's causing your Javascript error.
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>');

6 Comments

@user860869 - Try this answer, you are missing the single quotes because of the string is not well formed and there must be js error on the page. Take a look in the console.
tried this, isnt working, the issue isnt the list, its getting it to show up in the html
Did you check the demo before down voting me?
Also in your code there was an extra { near $(document).ready(function(){ I missed to mention that.
Did you remove the extra brace {? There is nothing to laugh dude we are trying to help you solve your problem.
|

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.