0

This is really bothering me and I can't figure out how to solve this problem. My code that is creating the problem is this:

$("#add-warmup").click(function(){
    $("#warmup").empty().prepend('<td><input type="text" name="distance-warm" maxlength="7" size="4"> miles</td><td><input type="text" name="duration-warm" maxlength="8" size="8" placeholder="HH:MM:SS" /></td><td>Warmup<input type="hidden" name="type-warm" value="Warmup" /></td><td><select name="shoe-warm"><option value=""><?= str_repeat('&nbsp;', 12); ?></option>></select></td>');
>});

I just want to click a link and have the current row replaced with actual value for input, but I keep getting the Unexpected token < error on the first part of the quote. Things as simple as .prepend('<p> test</p>'); work but this doesn.t

MikeM
  • 27,227
  • 4
  • 64
  • 80

4 Answers4

1

Try replacing this

<?= str_repeat('&nbsp;', 12); ?>

with

<?= str_repeat("&nbsp;", 12); ?>
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • I tried this, it seems like the error is right from the beginning http://gyazo.com/1f01eabd8e3acacc3eb534f5a88fc6cf.png?1365010212 – user2080921 Apr 03 '13 at 17:30
0

Does it work if you wrap what you're prepending?

$("#add-warmup").click(function(){

$("#warmup").empty().prepend($('<td><input type="text" name="distance-warm" maxlength="7" size="4"> miles</td> <td><input type="text" name="duration-warm" maxlength="8" size="8" placeholder="HH:MM:SS" /></td> <td>Warmup<input type="hidden" name="type-warm" value="Warmup" /></td>
<td><select name="shoe-warm"><option value=""><?= str_repeat('&nbsp;', 12); ?></option> </select></td>'));

});

Edit: From your screenshot: http://gyazo.com/1f01eabd8e3acacc3eb534f5a88fc6cf.png?1365010212

AHA! The culprit is shown! Your text starts on the line after the opening ' See here: Creating multiline strings in JavaScript

Community
  • 1
  • 1
Zach
  • 3,157
  • 1
  • 19
  • 32
0

There are a few things wrong with the posted code. You are using unescaped single quotes (') inside of a string using single quotes. <?= str_repeat('&nbsp;', 12); ?> should be <?= str_repeat(\'&nbsp;\', 12); ?> or <?= str_repeat("&nbsp;", 12); ?>.

Also note the fact that you are using PHP inside your jQuery. (Unless the JS is being generated by PHP.)

But your Unexpected token > error is from the fact that you have an extra > at the closing of your function.

Whymarrh
  • 13,139
  • 14
  • 57
  • 108
  • I don't think that matters. PHP is parsed on the server so what will be sent out to the client will only be the 12x  – Zach Apr 03 '13 at 17:27
0

With:

.prepend('<p>test</p>'); 

Try

.prepend('\<p\>test\<\/p\>');

also try to keep your HTML that you are prepending in one line.

I also noticed when i posted this your code was full of carriage returns. Remove these as well

Steve C
  • 2,638
  • 3
  • 25
  • 27