I copied this page's source in Aptana IDE for javascript. But, in the last lines:
<script language="JavaScript">
init();
</script>
</body>
</html>
it is showing at the init() line: syntax error, why? (when run, it works correctly)
There's a missing semicolon. Change
<input type="reset" onclick="lines=0;return true">
to
<input type="reset" onclick="lines=0;return true;">
Change it to
<script type="text/javascript">
I cannot reproduce this. Copy/pasting the code from that page into Aptana does not give me any errors. Make sure that a) you have the latest version of Aptana, and b) there are not any strange cop/paste artifacts in your code. Try pasting to notepad first and then from there to Aptana, to remove formatting information and see if it make a difference.
If you copy/pasted maybe the editor is with invalid characters, try checking for " or ' and replacing them with regular quotes and doboule quotes.
Copy Pasting source codes ofter cause this problem.
Related
Here is roughly the kind of code that I have.
<body>
<p>
...
</p>
<script>
function func()
{
...
for(...)
{
...
}
}
</script>
<p> ... </p>
</body>
HTML by itself indents properly, but when I put in the javascript everything screws up.
How do I deal with this?
You could try one of the multiple modes:
https://emacswiki.org/emacs/MultipleModes
http://wikemacs.org/wiki/JavaScript#Mix_html_and_Javascript
https://github.com/purcell/mmm-mode
https://github.com/vspinu/polymode
https://github.com/fgallina/multi-web-mode
Their goal is to have more than one mode at the same time in the same buffer, specially html and javascript.
What I tend to do is have blank lines in between my script tags and then switch over to javascript mode. The html would look like this with the blank line padding
<script type="text/javascript">
//some javascript
</script>
That seems to allow correct coloring and indenting. I also like to use js3-mode personally as it adds a bit more functionality than emacs' default javascript styling.
I've been scouring Google and SO for hours but can't seem to find an answer to this for the life of me!
All I want to do is preserve the line breaks entered into a <textarea> element by the user, to post the content via a jQuery $.ajax() call. If I simply submit the form to a page as usual, this works, but I've been told by my boss to use REST/AJAX.
Many, many posts on SO and across the net in general mention replacing \n's with <br />'s, or using white-space: pre-wrap; in the element's CSS. These solutions do not work for me as the line breaks simply don't show up in Chrome Developer Tools.
Code snippet:
<form id="addPostForm" role="form" method="post" action="/blog">
<div class="form-group">
<textarea rows="5" id="postBody" name="postBody"></textarea>
...more input controls
</div>
<button type="submit" class="btn btn-primary btn-block">Submit</button>
</form>
<script type="text/javascript">
$(document).on('submit', '#addPostForm', function() {
var postBody = $(this)[0].postBody.value;
...more code
});
</script>
When I enter e.g.:
"This is the first paragraph.
And here is another.
And yet another."
The postBody variable's value is:
"This is the first paragraph. And here is another. And yet another."
This is driving me crazy! Surely this shouldn't be as hard as it seems to be!
P.S. I don't think it should make a difference, but just in case anyone is wondering, I'm using Python/Pyramid, Jinja2 and Bootstrap 3 for this project.
Use this in JS
$("input[type=submit]").click(function(){
$.ajax({
type: "POST",
url: "yoururl",
data: $("#addPostForm").serialize()
(...)
});
});
In your server side code you can get POST value postBody with original spaces.
It would appear to me that this problem stems from the Chrome Dev Tools stripping the line breaks. Change the tool settings, or try something else like firebug.
Try splitting the lines by '\n' (yes I have tested this) and rejoin them with tags, check this out:
$('textarea').val().split('\n')
put this in your onclick function and set a breakpoint on it if you are using Chrome, it splits the lines into an array. if you join them with
.join('<br>')
you should be good to go.
Oops sorry for wasting your time, it was as simple as using $('#postBody').val() instead of $(this)[0].postBody.value. Thanks anyway to all commenters and answerers!
I have the following: http://jsfiddle.net/mVs9T/13/
Could someone please tell me why the output is printing
<br>
instead of:
<br/>
like here: http://f.imgtmp.com/Xjoq3.png
Yes, because that is how chrome interprets the <br /> tag. It's just aesthetic; you need not worry about it.
We added alert(txt); and it gave us <br/> - looks good to go.
That's browser behaviour. It shouldn't be a problem.
Since nothing can go between a <br> tag the /> part is not necessary. This is probably why the browser doesn't display it.
I was just wondering if you could please help. I am trying to get the
fancybox to load automatically once the page is rendered. However, I
got this error message 't is undefined' at line 18 (/js/fancybox/
jquery.fancybox-1.3.3.pack.js). At the moment, I am using jquery
version 1.4.2
Click me
<div style="display:none">
<div id="container">Fancybox Content Here .... </div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#profile').fancybox().trigger('click');
});
</script>
The funny thing is if I take the line below and run it in firebug
console then it WORKS!. Not sure what did I do wrong here. Your helps
would be grateful.
$('#profile').fancybox().trigger('click');
Thanks
I got the same problem. Testing with the unpacked version, i got "loading is undefined" in line 36 (fancybox 1.3.4). So I called "$.fancybox.init();" before triggering and it works correctly now.
Nope th reason is because the fancybox.js is included twice this is the file that has the core of fancy box
I've managed with the similar case in the way like this:
$(".some_wrapper").on('click', function(){
var lnk = $(this).find("a").first();
if (hr && ~cls.indexOf("fancybox-a")) {
$.fancybox(lnk);
}
});
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
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?
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.
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?