views:

65

answers:

3

django code:

return render_to_response(template_name, {
        "form": form,
    }, context_instance=RequestContext(request))

and html:

<script type="text/javascript">
        var a='{{form}}'

       alert(a) 
</script>

it's error is 'unterminated string literal',

and i see this in firebug :

<script type="text/javascript">
        var a='"<tr><th><label for="id_username">Username:</label></th><td><input id="id_username" type="text" class="textinput" name="username" maxlength="30" /></td></tr><tr><th><label for="id_email">Email (optional):</label></th><td><input id="id_email" type="text" class="textinput" name="email" /></td></tr>"';
            alert(a) 
    </script>

how do i alert the 'form' string .

thanks

A: 

I am unable to reproduce this error, pasting the above into a javascript console works without problems. Is it possible that there is something else done with a? Is above a simplification or exact javascript? Maybe you can show the entire HTML?

kb
+1  A: 

Maybe try putting in semi-colons at the ends of the lines in your Django template file?

<script type="text/javascript">
    var a='{{form}}';

    alert(a);
</script>

Odd though, I’m pretty sure semi-colons are optional there. Could you do a View Source in Firefox (instead of looking via Firebug), and see what HTML is actually being output by Django?

Paul D. Waite
Did that actually work? Crikey.
Paul D. Waite
+1  A: 

Check the HTML source of the page using "View source" rather than Firebug. I predict your {{form}} value has a line break in it, which will cause the error you're seeing.

Tim Down