|
making a menu I want to have the option of the current year, the 2 proceeding it and the next one...
this very very simple bit of code does the job well, I'm just wondering if there's any reason I should use an array instead of separate variables or if I'm breaking any other good practice rules...
<script>
d = new Date();
c = d.getFullYear();
a = c - 2;
b = c - 1;
d = c + 1;
</script>
and then further down, the menu
<ul>
<li><script>document.write('<a class="btn" href="report.php?y=' + a + '">' + a + '</a>');</script></li>
<li><script>document.write('<a class="btn" href="report.php?y=' + b + '">' + b + '</a>');</script></li>
<li><script>document.write('<a class="btn" href="report.php?y=' + c + '">' + c + '</a>');</script></li>
<li><script>document.write('<a class="btn" href="report.php?y=' + d + '">' + d + '</a>');</script></li>
</ul>
|
|
|
|
|
It's neither here nor there if you store the numbers in variables or use them in-line, however your choice of variable names is definitely against good practice. Call your variables things like previousYear, thisYear and nextYear.
If you're looking to try new things you could also use a "for" loop to write your links rather than doing it as you are. That way you can alter how many years back\forward you display rather than having to show four.
|
|
|
|
|
heh, wasn't too fussed about conventions like variable naming, was more interested in if there's any reason why declaring and assigning variables like that and then just referencing them in the spot I needed would be bad practice. I think if I was gonna make a loop for it, I'd change the page from being html to php, was really just a quick exercise in me just trying to keep it simple and keep the page html rather than php
|
|
|
|
|
I want to display specific fields from an external CSV file on a web site with using JavaScript. I tried to parse that file with using "Papa parse" like this: JSBin Link
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Parse remote CSV to HTML Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script src='http://d3js.org/d3.v3.min.js'></script>
<script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.2/papaparse.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.0/mustache.min.js'></script>
<script>
Papa.parse("https://dl.dropboxusercontent.com/s/wsnizh4lyugxd60/data.csv", {
download: true,
header: true,
complete: function(results) {
console.log(results);
var data = results.data;
var arrayLength = data.length;
for (var i = 0; i < arrayLength; i++) {
var newdiv = document.createElement('div');
newdiv.setAttribute('id', 'csvdata'+i.toString());
newdiv.innerHTML = 'Battery Level: '+data[i].batteryLevel.toString();
}
}
});
</script>
</body>
</html>
How can I display a specific data from this data set in a web site like:
Battery Level: 0.62
Altimeter Pressure: 99.44185
Horizontal Accuracy: 65
Can you give me an example in JSBin or JSfiddle?
|
|
|
|
|
Dear All,
I got a question!
why can't i put the script code after the div with class="jumbotorn" ?
I have tried to put it in the , and it's work!
Please helps me!
THANKS!
<body>
<div class="jumbotron">
<div align="center">
<h1 style="font-family:微軟正黑體;">行銷神語</h1>
<p id="pharse"></p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p>
</div>
</div>
<script>
function makePharse(){
var word1 = ["24/7","Multi-Tier","30,000 foot","B-to-B","Win-Win","Customer"];
var word2 = ["Empowered","Value-Added","Oriented","Focused","Aligned"];
var word3 = ["Process","Solution","Tipping-Point","Strategy","Vision"];
var rand1 = Math.floor(Math.random()*word1.length);
var rand2 = Math.floor(Math.random()*word2.length);
var pharse = word1[rand1]+""+word2[rand2]+"";
var pharseElement = document.getElementById("pharse");
pharseElement.innerHTML = pharse;
pharseElement.innerHTML = "TESt";
}
</script>
</body>
|
|
|
|
|
I do not agree that your script will work inside the head.
makePharse() is a function that you have to call it on some event say button click, so add an onclick to your button:
<a class="btn btn-primary btn-lg" href="#" role="button" onclick="makePharse()">Learn more</a>
and comment out the
|
|
|
|
|
|
I added the social media buttons facebook, twitter and linkedin to my page. Works ok on Chrome, Firefox and Safari. It blocks (and sometimes crashes) IE11, I didn't check previous versions yet.
I have no idea why, does anyone have an idea on how to solve it? Right now, I check if it is IE and just disable the tweet and facebook buttons (linkedin is working).
isIE is a boolean that indicates if it is Internet Explorer and "removes" the functionality. (for now)
Here's the rendered code:
twitter
where the button should be
<div id="tweetlink"></div>
<script>
if(!isIE){
document.getElementById('tweetlink').innerHTML =
"<div><a href='https ://twitter.com/share' class='twitter-share-button' data-url='urlhere' data-size='large'>Tweet</a></div>";
}
</script>
<script>
if(!isIE){
$(window).load(function () {$.getScript('<a href="http://platform.twitter.com/widgets.js">http://platform.twitter.com/widgets.js</a>');});
}
</script>
facebook
part 1
in the head
<meta property="og:url" content="urlhere" />
<meta property="og:type" content="website" />
<meta property="og:description" content="Solar Timelines for AFFECTS" />
<meta property="og:image" content="http://urlhere/Styles/Images/GUI/STAFF_96x96.png" />
part 2
right after the body tag
<script>
if(!isIE){
window.fbAsyncInit = function() {FB.init({appId: 'idhere',xfbml: true,version: 'v2.5'});};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
</script>
part 3
somewhere in the html where button should be
<div class="fb-like" data-href="urlhere" data-layout="button_count" data-action="like" data-show-faces="false" data-width="200" data-share="true"></div>
I did google it, but all results popped up with how to block the buttons, not on how to "not block" the page.
Feel free to look at it here[^] @ bottom of the page. In Chrome all buttons are there in IE only linkedin is there.
|
|
|
|
|
Hi,
can any one tell me how to create a site column in javascript.
I used this in my code:
var fieldschema2='Field Type="Number" DisplayName="AccordionOrder" Name="AccordionOrder" Required="False" Indexed="True" EnforceUniqueValues="True"/>'
but control is going to failure method.
I also tried Numeric and Integer types but column is not created.Let me know.
modified 13-Nov-15 2:05am.
|
|
|
|
|
What in the world are you talking about? What type of grid control is this for? It looks like you are trying to create sever-side properties in JS and expect it to work. We need a lot more details to understand what you are talking about.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have this JQuery here that I wrote a while ago. I use regex to extrack the price of the service. But now I added free services over a dollar amount, so I have instances in which service names now have 2 currency amounts.
So for example:
Free Shipping US48 $750.00 -- $0.00 USD
I just want the last match. Currently I get 2 matches,
$750.00
$0.00
Not sure if I should try and rewrite the Regex, or rewrite the JQuery.
I'm terrible with Regex, that's why I'm asking.
var rate_API_Text = $('input[name*="_lb_OP_AO_S2_Quotes_Original_Field"]:checked').next().text();
var rate_API_Index = rate_API_Text.indexOf("--");
var rate_API_Name = rate_API_Text.substr(0, rate_API_Index - 1);
$('[id*="_lbl_OP_AO_S2_Dashboard_StatusMessage_Field"]').text(rate_API_Name);
var rate_Amount = "$0.00";
var re_ratePlan = new RegExp("(\\$[0-9,]+(\\.[0-9]{2})?)");
var txt_ratePlan = $('input[name*="_lb_OP_AO_S2_Quotes_Original_Field"]:checked').next().text();
var match_ratePlan = re_ratePlan.exec(txt_ratePlan);
if (match_ratePlan.length !== null || match_ratePlan.length > 0) {
for (var i = 0; i < match_ratePlan.length; i++) {
rate_Amount = match_ratePlan[i] + "\n";
break;
}
if (match_ratePlan !== null) {
$('[id*="_lbl_OP_AO_S2_Dashboard_Calc_RateAmount_Field"]').text(rate_Amount);
}
else {
$('[id*="_lbl_OP_AO_S2_Dashboard_Calc_RateAmount_Field"]').text("$0.00");
$('[id*="_txt_Estimated_Rate_Field"]').val(rate_Amount);
}
}
|
|
|
|
|
I changed the source of the regex to the latter part of the string index instead.
That's what happens when you have to go back to code you wrote years ago. You forget exactly how it operates and you have to rethink it again.
var rate_API_Text = $('input[name*="_lb_OP_AO_S2_Quotes_Original_Field"]:checked').next().text();
var n = rate_API_Text.indexOf("--");
var rate_API_Name = rate_API_Text.substr(0, n - 1);
$('[id*="_lbl_OP_AO_S2_Dashboard_StatusMessage_Field"]').text(rate_API_Name);
var rate_Amount = rate_API_Text.substr(n, rate_API_Text.length - 1);
var re_ratePlan = new RegExp("(\\$[0-9,]+(\\.[0-9]{2})?)");
var match_ratePlan = re_ratePlan.exec(rate_Amount);
if (match_ratePlan.length !== null || match_ratePlan.length > 0) {
for (var i = 0; i < match_ratePlan.length; i++) {
rate_Amount = match_ratePlan[i] + "\n";
break;
}
if (match_ratePlan !== null) {
$('[id*="_lbl_OP_AO_S2_Dashboard_Calc_RateAmount_Field"]').text(rate_Amount);
}
else {
$('[id*="_lbl_OP_AO_S2_Dashboard_Calc_RateAmount_Field"]').text("$0.00");
$('[id*="_txt_Estimated_Rate_Field"]').val(rate_Amount);
}
}
|
|
|
|
|
Can anyone help am new in JavaScript environment I want to create a JavaScript tour guide library that will allow re-usability of the tour guide across various web applications.
|
|
|
|
|
Member 11984883 wrote: Can anyone help Not unless you explain exactly what help you want.
|
|
|
|
|
 ok thanks what I want to do is current I have a web application that is running and I have a bootstrap tour guide that is running, the problem with this one is each view has the own script for that tour guide that referencing the control ID on that view, now I want to develop one dynamic JavaScript tour guide library that I can use to the rest of my web application and even to the other .Net applications. hopping am clear now see what am current having now.
$(function () {
var startIndex = 0;
var tour = new Tour({
storage: window.localStorage
});
startIndex = tour._options.steps.length;
tour.addSteps([
{
element: "#first-name",
title: "Searching for an employee",
content: "To search for the employee to add, please type in the employee name or surname in the textbox provided.<br> Once you have found the employee, all his/her details will be pulled on your behalf.",
placement: "top",
},
{
element: "#surname",
title: "Searching for employee",
content: "Alternatively, you can search the employee by typing into the provided <strong>Surname</strong> textbox provided.",
placement: "top"
},
{
element: "#engagements",
title: "how to create engagements",
content: "To create engagements click on this engagements bottun .",
placement: "top"
},
{
element: "#administrator",
title: "how to do administration",
content: "To do administration click on the administration bottun.",
placement: "top"
},
{
element: "#dropdown",
title: "how to logout ",
content: "To logout on this system click on the drop down next to your name and click logout.",
placement: "top",
},
]);
tour.init();
tour.start();
});
|
|
|
|
|
Rather than re-inventing the wheel, have you considered using one of the many existing libraries that provide this type of functionality?
For example:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
<java>
I am trying to store user input (string values) into a 2d array but am unable to figure out how to do a for loop for String values.
User will input a First Name, Last Name, Phone, and Age
public class Lab2
{
public static void main(String[] args) {
//Example Data but need it entered by a user
String [][] array = {
{"Ryan", "Smith", "555555555", "12"},
{"George", "Young", "123456789", "52"},
{"Frank", "McDonnell", "555123789", "18"}
};
//Create a for loop for user input
//Displays the entire array
for (int row=0; row<array.length; row++){
="" for="" (int="" col="0;" <array[row].length;="" col++){
="" system.out.print(array[row][col]+"="" ");
="" }
="" system.out.println();
}
}
}
<="" java="">
|
|
|
|
|
Does this have anything to do with Javascript?
|
|
|
|
|
I want to make a web page contains headline news from differnt web sites.
I want to refresh it daily.
I prefere to do this by a javascript code.
Can any one help me?
|
|
|
|
|
You could possibly fetch the RSS feeds from different news websites, like BBC etc. They all provide you with functionality to fetch the latest feeds from their servers and you can then render those RSS feeds on your website.
The website would then act as an RSS feed reader. Before you begin, I would recommend that you read about RSS[^], RSS feeds (same as RSS) and RSS Readers (the application which pulls the RSS feeds and then display them in the device). Understand them and them implement the service in your application.
Also, why would you like to pull it using JavaScript when you can pull it using your server-side language too? Which would be much more fast and efficient.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
thanks for replaying.
I need to feed my web page from sites don't all proceed rss feeds (such as http://ara.reuters.com)
This is a personal web page for me only to read news more easily.
|
|
|
|
|
I want to load a png image in base64 to html5 canvas element. I have this code:
<html>
<head></head>
<body>
<canvas id="pageCanvas"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("pageCanvas");
var ctx = canvas.getContext("2d");
var imageData ="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oMCRUiMrIBQVkAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADElEQVQI12NgoC4AAABQAAEiE+h1AAAAAElFTkSuQmCC";
var imageObj = new Image();
imageObj.src = imageData;
ctx.drawImage(imageObj, 50, 100);
</script>
</body>
</html>
The above code working well in IE, chrome, Microsoft edge. But in Firefox the image was not displayed. It display blank page. Sometime when we reload the page then it displayed an image in canvas.
Best,
Parthi
|
|
|
|
|
There is no such code that works "sometimes". Code either works or doesn't work, but it can depend on the underlying libraries and stuff like that so the first time it doesn't work because the framework isn't ready and then works because everything is set up.
But it is still not convincing to believe that a reload fixes everything. Take this, press F12 and try to look for the error that this image gives. Console would log the error and you can see that error to find a solution, or post it here so we may help you.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
yes, i checked the console window but it does show any error.
|
|
|
|
|
I'm doing an assignment with an order form and was wondering if there is a function that will auto fill the cost field after entering the quantity field?
|
|
|
|
|