This question already has answers here:
How to interpolate variables in strings in JavaScript, without concatenation?
(17 answers)
Closed 5 years ago.
As I'm sure you're about to see for yourself, I'm relatively new at coding. I've been struggling to get the png image from json file to show up on my codepen. I've already tried several suggestions I found in my Stackoverflow searches but nothing I've tried seems to work for my situation.
Here's the link to my codepen:
http://codepen.io/mbabaian/pen/MpjbZv
The code I'm trying to use to get the image at this time is:
var currentIcon = wd.current.condition.icon;
// weather icon settings
$("#current-icon").html("<img src='wd.current.condition.icon' alt='weather icon'/> ");
And here's the particular json data where the image is located:
https://api.apixu.com/v1/current.json?key=68629a769f564f9bb6450153170703&q=auto:ip
Please let me know if you need any additional information from me about this. Thanks in advance.
Simply use
$("#current-icon").html("<img src='"+wd.current.condition.icon+"' alt='weather icon'/> ");
Here is your updated codepen
You create currentIcon, use it
$("#current-icon").html('<img src="'+currentIcon+'" alt="weather icon"/>');
Related
This question already has answers here:
Link to Flask static files with url_for
(2 answers)
Closed 2 years ago.
Please refer to this post where a similar question is already answered: Link to Flask static files with url_for .
I have a simple embed html block that relates to a filepath.
<embed src="/static/filename.txt">
However the filename changes(the path stays the same) as the content inside file changes time to time. Hence, I am currently passing the filename to the html template with the following code(flask)
return render_template('view.html', filename = filename )
Is there way to pass the file name in to embed html tag? The goal result to be something like this?
<embed src="/static/{filename}.txt">
where the {filename} changes based on passed data from flask.
Any help or suggestion of implementation is appreciated!
Yes.
<embed src="/static/{{filename}}.txt">
Did you try using template strings? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
It allows you to insert a variable inside a string.
Your example would look something like this:
<embed src=`/static/${filename}.txt`>
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 4 years ago.
Having a bad day. This one has stumped me all morning. All the solutions I've found have stopped one step short of where I need to go.
I have a legacy PHP/JS app that I'm working on. Rather than trying to explain it, I'll just show what I need to do.
<?php
$phpDate_1 = new Date($someDate);
$phpDate_2 = new Date($someOtherDate);
//...There are a bunch of these
$phpDate_n = new Date($endOfTime);
<script language="javascript">
function myFunction() {
var line = aUserSelection; //an int from user which tells me what date to use
//Next line is the problem. I'm trying to pull the month from the appropriate PHP date into the JS variable.
var theMonth = "<?php echo $phpDate_" + line + "->getMonth();?>";
}
</script>
?>
I must have tried 20-30 combinations of single and double quotes, escapes, dots, pluses, and so on, but I keep getting errors over the "line" part. Unexpected character, encapsed strings, etc.
Hoping someone can point me in the right direction because my brain is fried at this point. Answers in pure JS and PHP only please because that's how the app is built. Thanks.
You need to close your php (?>) before outputting the javascript to fix the syntax error that you got.
However, with that said, you are trying to incorporate the javascript line variable into the variable name for $phpDate, to generate something like $phpDate_1.
If you don't want to go with an AJAX solution, your best bet would be to output each line's date into a javascript array. This is strongly discouraged, but if this is a legacy application that you cannot make many changes to, this might be your only option.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Attach File Through mailto URI
I have an HTML link like
Send Mail
I would like attach a file in the Mail Client when a User click the this link.
Is it possible in JavaScript or using jQuery, html5?
You can try MS ActiveX:
var OA = new ActiveXObject('Outlook.Application');
var OAItem = OA.CreateItem(0);
var OAItemAtms = OAItem.Attachments;
OAItemAtms.add('http://foo.com/some_image.png');
You can read more on this here - compose-and-send-e-mail-from-javascript-by-using-outlook
No.
And of course JQuery won't help since that is also Javascript.
You really need something serverside to manage this for you.
This question already has answers here:
Replace function not replacing [duplicate]
(2 answers)
Closed 8 years ago.
I have written a simple code in a .js file (in Zend framework, but I dont think it matters)
var location = "localhost:8080/mymodule/id/1#";
location.replace(/\#/g, "");
alert(location.valueOf());
return;
but I dont know why I can not see the result I want.
I get my page url and want to omit all number signs appears in it. but the code above does nothing.
please help
location is a bad name to use for a variable since it collides with the window.location variable used for the actual browser page location.
If you change location to loc in your above code, and then also add loc = in front of the loc.replace() call (since replace() doesn't modify the input, but instead returns the new version), your code works.
replace will not change the value of the original string, you need to assign the result to a new variable -
var newString = location.replace(/#/g, "");
alert(newString);
Demo - http://jsfiddle.net/5H5uZ/
It can be done in one line. This is the result you look for?
alert("localhost:8080/mymodule/id/1#".replace(/#/g,''));
//=> alerts 'localhost:8080/mymodule/id/1'
This question already has answers here:
Get formatted HTML from CKEditor
(12 answers)
Closed 9 years ago.
I'm using CKEditor in my web app, but I don't know how to get html content from it.http://cksource.com/ckeditor
I searched online found one said using getData() method, but there is no getData() method after typing dot after the controler. Can anyone give me a sample code to get html from CKEditor controller? Thank you in advance.
To get htmlData from editor you should use the code snippet bellow:
var htmldata = CKEDITOR.instances.Editor.document.getBody().getHtml();
If this solution won't work, check if you have BBCode plugins installed.
getData() is part of the javascript API.
It seems that you are trying to do it at the server side, so you should check the specific API of whatever wrapper you are using, or just check the value in the form posted data.
Not sure how you're implementing usage of the CKEditor.
If you're replacing a textarea using CKEDITOR.replace( 'NameOfTextarea', this should work:
CKEDITOR.instances.NameOfTextarea.on( 'instanceReady', function( instanceReadyEventObj )
{
var editorInstanceData = CKEDITOR.instances.NameOfTextarea.getData();
alert( editorInstanceData );
});
Replace "NameOfTextarea" with the name of your textarea, it's used to name the editor instance.
It's a good idea to put it inside the "on instanceReady" function so you don't get an undefined error.
Joe