Why my jquery isn't displayed by browser? - javascript

so i am new to jq and i am trying to run this code but the browser doesn't show anything, tried to link the script library before ending tag of body.
Thanks!
<!DOCTYPE html>
<html>
enter code here
<head>
<meta charset="utf-8">
<title>Data Types</title>
<script src="jq/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
document.write(3.25 + 1000);
document.write('<br>' + 5 - 1000);
var1 = "Buna";
var2 = "Ziua";
document.write("<br>Concatenare siruri:" + var1 + var2 + '<br>');
a = true;
document.write(a);
var = fructe['mere', 'pere', 'caise'];
document.write('<br>' + fructe[1]);
</script>
</body>
</html>

You should fix this line:
var = fructe['mere', 'pere', 'caise'];
To
var fructe = ['mere', 'pere', 'caise'];

Related

How do you "convert" $('#yourname').val(); to vanilla javascript?

Just need help getting the vanilla javascript version of $('#yourname').val(); part of var name=$('#yourname').val();
There are numerous selectors of JavaScript in order to do this.
You can find some here, here, and here.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<input type="hidden" id="someID" value="625413">
<script>
var a = document.getElementById("someID").value;
var b = $("#someID").val();
var c = document.querySelector("#someID").value;
alert(a + " / " + b + " / " + c);
</script>
</body>
</html>
var a = document.getElementById("someID").value; is the 'classic' example of Vanilla JavaScript.

Need to store html date input in JS var

I need help with JS and html. I need to store <input type = "date" id = "date"> in JS var. If you try to store the date in simple var and try to print it instead of your chosen date you get printed "undefined" :
$("#printDate").click(function(){
var dateVar = ($("#date").val());
$("#results").append("<p>" + dateVar + "</p>")
});
If you try to store the date in the dateVar using new Date() you get printed "Invalid date":
$("#printDate").click(function(){
var dateVar = new Date($("#date").val());
$("#results").append("<p>" + dateVar + "</p>")
});
Thank you for any kind of help!
upd: full page code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
`<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">`</script>
</head>
<body>
<div id="results"></div>
<input type="date" id = "dateInput">
<button id = "printDate">PrintDate</button>
<script>
$("#printDate").click(function(){
var dateVar = new Date($("#date").val());
$("#results").append("<p>" + dateVar + "</p>")
});
</script>
</body>
</html>
$("#printDate").click(function(){
var dateVar = new Date($("#dateInput").val());
$("#results").append("<p>" + dateVar + "</p>")
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">`</script>
</head>
<body>
<div id="results"></div>
<input type="date" id = "dateInput">
<button id = "printDate">PrintDate</button>
</body>
</html>
The only problem with your code is you are targetting wrong id i.e $("#date") instead of $("#dateInput")
<div id="results"></div>
<input type="date" id="dateInput">
<button id="printDate">PrintDate</button>
<script>
$("#printDate").click(function(){
var dateVar = new Date($("#dateInput").val());
$("#results").append("<p>" + dateVar + "</p>")
});
</script>
You have a typing error.

Google Feed API for RSS is not showing current events

I am attempting to use Google Feed API to display three current event listings for our homepage. This is to circumvent some of the issues we are having with a third part calendar application.
However, with the feed limit set to 3, the only listings that will show up for me are from Jan. 18. Is there a way to make the code show only current or future events?
Thanks in advance for any help.
HTML
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="http://www.google.com/jsapi">
</script>
</head>
<body>
<div id="feed"></div>
</body>
</html>
JavaScript
google.load("feeds", "1");
var feedcontainer=document.getElementById("feed");
var feedurl="http://25livepub.collegenet.com/calendars/publishers-calendar-7.rss";
var feedlimit = 3;
var rssoutput = '';
function rssfeedsetup(){
var feedpointer=new google.feeds.Feed(feedurl);
feedpointer.setNumEntries(feedlimit) ;
feedpointer.load(displayfeed);
}
function displayfeed(result){
if (!result.error){
var thefeeds=result.feed.entries;
for (var i=0; i<thefeeds.length; i++){
var untrimContent = thefeeds[i].content;
var trimContent = untrimContent.split("<br>", 2);
rssoutput+="<div><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></div>" + trimContent;
feedcontainer.innerHTML=rssoutput;
}
} else {
feedcontainer.innerHTML = "Error Loading Events";
}
}
window.onload=function(){
rssfeedsetup();
};

javascript code working in jsfiddle but not working in the browser [duplicate]

This question already has answers here:
JSFiddle code not working in my own page
(3 answers)
Closed 8 years ago.
my code is working in jsfiddle but not working in the browser i dont know what i missed here could you please check it and tell me the solution. i google it but i am not getting correct solution please help me
this is jsfiddle link http://jsfiddle.net/pLTrJ/9/
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"> </script>
</head>
<script type="text/javascript">
var random = 0;
var theDiv = document.getElementById("showVal");
updateTheDiv(9,0);
function updateTheDiv(inRange, inMin) {
random = (Math.random()*inRange+inMin)|0;
theDiv.innerHTML = random;
var nextCall = (Math.random()*1000)|0;
setTimeout(function() {
updateTheDiv(inRange, inMin);
}, nextCall);
}
</script>
<body>
<div id="showVal"></div>
</body>
</html>
jsfiddle has wrapped it automatically in the onload event. You haven't done this in your HTML page, so when it runs in the browser you're trying to get hold of the div before it's been rendered, so theDiv is null.
The below should work:
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"> </script>
</head>
<script type="text/javascript">
window.onload = function () {
var random = 0;
var theDiv = document.getElementById("showVal");
updateTheDiv(9, 0);
function updateTheDiv(inRange, inMin) {
random = (Math.random() * inRange + inMin) | 0;
theDiv.innerHTML = random;
var nextCall = (Math.random() * 1000) | 0;
setTimeout(function () {
updateTheDiv(inRange, inMin);
}, nextCall);
}
}
</script>
<body>
<div id="showVal">
</div>
</body>
</html>
Try this in your Browser ;)
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"> </script>
</head>
<body>
<div id="showVal"></div>
</body>
<script type="text/javascript">
var random = 0;
var theDiv = document.getElementById("showVal");
updateTheDiv(9,0);
function updateTheDiv(inRange, inMin) {
random = (Math.random()*inRange+inMin)|0;
theDiv.innerHTML = random;
var nextCall = (Math.random()*1000)|0;
setTimeout(function() {
updateTheDiv(inRange, inMin);
}, nextCall);
}
</script>
</html>
(I just put the script to the bottom. So the script loads after your element is set.)

converting html tags and the content to string

my question is I need to create a string from the result of event.content. Event.content returns me an entry including html tags. I can use it like container.innerHTML = event.content. I need the event.content as a string. I tried to do something like this:
var a = '' + event.content;
But it doesn't work. Here the result of event.content:
<img src="http://image.weather.com/web/common/wxicons/31/30.gif?12122006" alt="" />Partly Cloudy, and 84 ° F. For more details?
I can't convert this into string in javascript. Is it possible? I also tried String(event.content). Ok I put my whole code.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Hava Durumu</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("feeds", "1");
function havabas(){
var feed = new google.feeds.Feed("http://rss.weather.com/weather/rss/local/TUXX0014? cm_ven=LWO&cm_cat=rss&par=LWO_rss");
feed.load(function(result) {
if (!result.error) {
var entry = result.feed.entries[0];
var container = document.getElementById("weather");
var c = entry.content;
var regex = /<img.*?src="(.*?)".*?>.*?([0-9]+\s*°)/;
var results = regex.exec(entry.content);
var html = '<img src= ' + results[1] + ' alt="" /> ' + results[2];
container.innerHTML = html;
}
});
}
function initialize() {
havabas();
setInterval(function(){havabas()},2000);
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="weather"></div>
</body>
</html>
Your regex is invalid. It does not match the string from entry.content. The reason for this is °. Change your code to this:
var regex = /<img.*?src="(.*?)".*?>.*?([0-9]+)/;
var results = regex.exec(entry.content);
var html = '<img src= ' + results[1] + ' alt="" /> ' + results[2] + ' °';
DEMO
Probably you forgot to escape either the sigle quotes or double quotes with a backlash? This is a valid string -
var string="<img src=\"http://image.weather.com/web/common/wxicons/31/30.gif?12122006\" alt=\"\" />Partly Cloudy, and 84 ° F. For more details?";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
function get1()
{
var i='<img src="http://image.weather.com/web/common/wxicons/31/30.gif?12122006" alt="" />Partly Cloudy, and 84 ° F. For more details?';
var j='\'' +i+ '\'';
alert(j);
}
</script>
<BODY onload='get1();'>
</BODY>
</HTML>
Please try this

Categories

Resources