|
They are saying they want to run it only with class, if we add ids and if we use same id some where when we write functions or use popups we may get errors. Second this is what they are using here is we don't write jquery in aspx or ascx page but we have files called xx.js, common.js, Popup.js etc there we write all jquery, that is why we are not using ids.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Sure you can. You can get to any element in the html so long as you know it's position in relation to other elements.
I like to think of this approach as somewhat akin to climbing a tree with your eyes closed. So long as you've looked at the tree first and know where the branches are in relation to one another, you can climb away. It's fraught with danger though, because you can remember the relationships wrong or they can change from when you look at them to when you try to use them.
It may well be a poor analogy - but it works for me.
--
You can take advantage of a function querySelectorAll for this task. It allows you to pass in a string which would serve as a css selector for the element.
In your case, you want to target a button element that's contained in an element with the footer class. The css selector for this would be .footer button
See below for a short demo that allows you to hide/show the target button.
<!DOCTYPE html>
<html>
<head>
<script>
"use strict";
function byId(e){return document.getElementById(e);}
window.addEventListener('load', onDocLoaded, false);
function onDocLoaded()
{
byId('mHideShowBtn').addEventListener('click',onHideShowBtnClick,false);
}
function onHideShowBtnClick(e)
{
var tgtBtn = document.querySelectorAll('.footer button')[0];
if (tgtBtn.style.display == '')
tgtBtn.style.display = 'none';
else
tgtBtn.style.display = '';
}
</script>
<style>
</style>
</head>
<body>
<div class="footer" style="position: absolute; bottom: 0px; width: 95%; margin-left: 2%; z-index: 3;">
<button style="width: 80px; background: url(http://localhost/ELMS/Image.axd?t=Close&r=211&g=211&b=211&p=20&h=25) 0% 0% no-repeat transparent;">Close</button>
</div>
<hr>
<button id='mHideShowBtn'>Hide/Show</button>
</body>
</html>
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
|
|
|
|
|
Hi,
I have a js file in which code is written as below, I am not understand some of the statements from here, can you please let me know why and in which contexts we use these statements.
1. ELMS.Constructs.Popup = function (parameters) {
2. jQuery.fn.convertLinkToPopupWithClose =
3. this.containerDiv = $("<div class='container'></div>").css (xxxx...),
I am not use what are these why are we trying to assign them to some values? how, where and when should we use them? Can you please explain them little bit?
if (!ELMS.Constructs) {
ELMS.Constructs = {};
}
ELMS.Constructs.Popup = function (parameters) {
var _that = this;
this.offset = 10;
this.parameters = parameters;
this.displayed = false;
this.waitElement = ELMS.Common.generateWaitDiv("Loading Popup...");
this.outsideContainerDiv = $("<div class=\"popup\"></div>")
.css({
width: "450px",
top: this.parameters.y.toString() + "px",
left: this.parameters.x.toString() + "px",
overflow: "hidden",
paddingRight: "10px",
paddingBottom: "10px",
height: "400px"
});
this.containerDiv = $("<div class='container'></div>")
.css({
position: "relative",
marginTop: this.offset.toString() + "px",
width: "100%",
paddingBottom: "36px",
height: "100%"
})
.appendTo(this.outsideContainerDiv);
$("<div class='handle'></div>").appendTo(this.outsideContainerDiv);
this.createTitle = function (title) {
_that.titleH2 = $("<h2>" + title + "</h2>");
_that.containerDiv.prepend(_that.titleH2);
};
if (this.parameters.title)
this.createTitle(parameters.title);
this.setTitle = function (title) {
if (!this.titleH2)
this.createTitle(title);
else
this.titleH2.text(title);
};
this.iframe = $('<iframe class="popup" frameBorder="0" allowTransparency="true" name="PopupIframe"></iframe>')
.css({
width: "100%",
height: "100%",
position: "absolute",
zIndex: 1,
marginTop: "25px",
top: 0
});
this.iframe.appendTo(this.outsideContainerDiv);
this.preClose = function () {
if (_that.parameters.preCloseFunction)
if (!_that.parameters.preCloseFunction(_that))
return false;
return true;
};
this.runningInternalClose = false;
this.internalCloseFunction = function () {
if (_that.runningInternalClose)
return;
_that.runningInternalClose = true;
if (_that.iframe[0].contentWindow && _that.iframe[0].contentWindow.ELMS && _that.iframe[0].contentWindow.ELMS.Common.isDirty)
if (!confirm("There are unsaved changes. Would you like to leave this page? Any unsaved changes will be lost."))
return false;
if (!_that.preClose())
return false;
if (_that.parameters.closeDestroys)
_that.destroy.apply(_that, arguments);
else
_that.hide.apply(_that, arguments);
if (_that.parameters.closeInformsParent) {
var message = { action: "Close" };
if (_that.parameters.closePayload)
message.payload = _that.parameters.closePayload;
_that.sendMessage(message);
}
_that.runningInternalClose = false;
return true;
};
this.upperClose = $("<image alt='Close Popup' border='0' src='" + ELMS.Common.root + "/images/Popup-Close-Button.png' />")
.css(
{
position: "absolute",
border: "none",
fontSize: 0,
backgroundColor: "transparent",
height: "25px",
width: "25px",
right: "0",
top: "0",
cursor: "pointer"
}
)
.click(this.internalCloseFunction)
.appendTo(this.outsideContainerDiv);
if (this.parameters.showFooter) {
this.footer = $("<div class=\"footer\"></div>")
.css({
position: "absolute",
bottom: 0,
width: "95%",
marginLeft: "2%",
zIndex: 3
});
if (this.parameters.showClose) {
if (event.target.toString().match(/[^\/]+$/)[0].toString().split('?')[0].toString().split('&')[0].toString() != "Popup_ViewWaitingList.aspx") {
this.closeButton = $("<button style=\"background:transparent url('" + ELMS.Common.root + "/Image.axd?t=Close&r=211&g=211&b=211&p=20&h=25') left top no-repeat;\">Close</button>").appendTo(this.footer);
ELMS.Common.handleDynamicButtonImages(this.closeButton);
this.closeButton.click(this.internalCloseFunction);
}
}
this.footer.appendTo(this.containerDiv);
}
this.messageCallbacks = [];
this.addMessageCallback = function (callback) {
this.messageCallbacks.push(callback);
return this;
};
var _popup_this = this;
this.sendMessage = function (payload) {
if (payload.action.toLowerCase() == "resize") {
this.resize({ width: payload.payload.width, height: payload.payload.height });
} else if (payload.action.toLowerCase() == "redirect") {
_popup_this.destroy();
ELMS.Common.getTopLevelWindow().ELMS.Common.wait();
ELMS.Common.getTopLevelWindow().location.href = ELMS.Common.resolveUrl(payload.payload.url || payload.payload.redirectUrl);
} else if (_popup_this.messageCallbacks.length == 0 && payload.action.toLowerCase() == "close") {
if (_popup_this.parameters.showClose && _popup_this.closeButton)
_popup_this.internalCloseFunction();
else
_popup_this.destroy();
} else {
for (var i = 0, callback; callback = _popup_this.messageCallbacks[i]; i++) {
callback(_popup_this, payload);
}
$(ELMS.Common.getTopLevelWindow().document).trigger("ELMS:ReceivePopupMessage", [ _popup_this , payload ]);
}
};
this.setPreCloseFunction = function (preCloseFunction) {
this.parameters.preCloseFunction = preCloseFunction;
};
this.show = function (title, element) {
if (element) {
ELMS.Common.dimElementBackground(element);
} else {
ELMS.Common.dimBackground();
}
var div = this.outsideContainerDiv,
body = ELMS.Common.getTopLevelWindow().document.body;
if (div.parent().length > 0) {
div.show();
} else {
if ($.browser.msie && parseInt($.browser.version, 10) <= 8) {
var html = $("html")[0];
if (html.scrollTop > 0)
div.css("top", (25 + html.scrollTop).toString() + "px");
} else {
var bodyScrollTop = document.scrollTop ? document.scrollTop : body.scrollTop;
if (bodyScrollTop > 0)
div.css("top", (25 + bodyScrollTop).toString() + "px");
}
div.appendTo(body);
if (!this.parameters.sourceIframe && !this.parameters.sourceElement && this.parameters.url)
this.iframe.prop("src", this.parameters.url);
if (!this.parameters.sourceIframe)
this.wait();
this.iframe.load(this.iframeLoaded);
if (this.parameters.sourceIframe)
this.iframeLoaded({ target: this.iframe[0] });
div.draggable({ handle: ".handle" });
}
this.displayed = true;
return this;
};
this.dimBackground = function () {
var div = this.outsideContainerDiv,
height = div.height() - this.offset,
width = div.width() + 1;
$("<div class='dimBG'></div>")
.css({
position: "absolute",
top: this.offset.toString() + "px",
left: 0,
height: height.toString() + "px",
width: width.toString() + "px",
background: "transparent url('" + ELMS.Common.root + "/images/Transparent-Bg.png') left top repeat",
zIndex: 3
})
.appendTo(div);
this.upperClose.css("cursor", "default").off("click", this.internalCloseFunction);
};
this.undimBackground = function () {
this.outsideContainerDiv.find(".dimBG").remove();
this.upperClose.css("cursor", "pointer").click(this.internalCloseFunction);
};
this.wait = function (message) {
this.outsideContainerDiv.data("oldHeight", this.outsideContainerDiv.height());
this.outsideContainerDiv.height(this.containerDiv.outerHeight() + 10);
this.waitElement.find("p").text(message);
this.dimBackground();
this.waitElement.appendTo(this.containerDiv).center(this.containerDiv);
};
this.unwait = function () {
this.outsideContainerDiv.height(this.outsideContainerDiv.data("oldHeight"));
this.undimBackground();
this.waitElement.remove();
};
this.iframeContentLoaded = function (popup) {
if (popup) {
var urlChanged = popup.currentUrl && popup.currentUrl != popup.iframe[0].contentWindow.location.href;
popup.currentUrl = popup.iframe[0].contentWindow.location.href;
if (popup.iframe[0].contentWindow.ELMS)
popup.iframe[0].contentWindow.ELMS.ParentPopup = popup;
$(popup.iframe[0].contentWindow).resize(function () {
if (!popup.resizing)
popup.resize({ basedOnContent: true });
});
if (popup.parameters.showTitle && !popup.parameters.title) {
var text = $(popup.iframe[0].contentDocument).find(".title,h2").first().remove().text();
if (popup.titleH2)
popup.titleH2.text(text);
else
popup.createTitle(text);
}
var actionButtons = $(popup.iframe[0].contentDocument.body).find(".action-buttons");
if (popup.parameters.showFooter && actionButtons.length > 0) {
var clone;
if (urlChanged && popup.parameters.processedActionButtons) {
this.footer.find(".action-buttons").remove();
popup.parameters.processedActionButtons = false;
}
if (popup.parameters.processedActionButtons) {
clone = this.footer.find(".action-buttons").find("button,input[type='submit']").remove();
popup.parameters.processedActionButtons = false;
}
if (!popup.parameters.processedActionButtons) {
popup.parameters.processedActionButtons = true;
clone = actionButtons.clone().css({
float: "left",
margin: 0,
padding: 0,
border: "none",
width: "auto"
});
if (popup.parameters.showClose && this.closeButton.parent().length > 0) {
this.closeButton.before(clone);
if (actionButtons.find("input[value='Cancel']").length > 0)
this.closeButton.remove();
} else
clone.appendTo(this.footer);
}
var sourceButtons = actionButtons.find("button,input[type='submit']");
clone.find("button,input[type='submit']").each(function (index, button) {
var sourceButton = sourceButtons[index];
button = $(button);
button
.click(function (event) {
$(sourceButton).click();
});
button.data(popup.iframe[0].contentWindow.$(sourceButton).data());
popup.iframe[0].contentWindow.$("#" + sourceButton.id)
.on("prop", function (event) {
button.prop.apply(button, [].splice.call(arguments, 1));
})
.on("attr", function (event) {
button.attr.apply(button, [].splice.call(arguments, 1));
})
.on("removeProp", function (event) {
button.removeProp.apply(button, [].splice.call(arguments, 1));
})
.on("removeAttr", function (event) {
button.removeAttr.apply(button, [].splice.call(arguments, 1));
});
});
popup.containerDiv.height(popup.containerDiv.height() - actionButtons.height());
actionButtons.hide();
if (popup.parameters.showClose && actionButtons.has("input[type='submit'][value='Close']").length > 0)
this.closeButton.remove();
}
if (popup.parameters.sourceElement) {
var form = $("#form1")[0];
if (form.removeAttribute)
form.removeAttribute("target");
else
form.target = null;
form.action = form.action.substring(0, form.action.length - 6);
}
popup.unwait();
window.setTimeout(function () {
popup.resize({ load: true, urlChanged: urlChanged });
}, 250);
}
},
this.iframeLoaded = function (event) {
var popup = ELMS.WebControls.Popup.getPopup(event.target);
if (popup.parameters.sourceIframe && popup.parameters.sourceIframe.tagName && popup.parameters.sourceIframe.tagName == "IFRAME") {
popup.iframe[0].contentWindow.document.open();
var html = $(popup.parameters.sourceIframe.contentWindow.document.documentElement).html();
if ($.browser.msie)
html = html.replace(/\<script/gi, "<script defer='true'");
popup.iframe[0].contentWindow.document.write(html)
popup.iframe[0].contentWindow.document.close();
}
$(event.target.contentDocument).ready
(
function () {
popup.iframeContentLoaded(popup);
}
);
};
this.hide = function (parameters) {
parameters = $.extend({ destroy: true, runCloseFunction: false }, parameters);
if (parameters.runCloseFunction && !_that.preClose.call(this))
return;
var topWindow = ELMS.Common.getTopLevelWindow();
if (this.displayed) {
if (parameters.destroy)
this.outsideContainerDiv.remove();
else
this.outsideContainerDiv.hide();
if (parameters.element) {
ELMS.Common.undimElementBackground(element);
} else {
ELMS.Common.undimBackground();
}
this.displayed = false;
}
if (parameters.destroy) {
var popups = topWindow.ELMS.Page.Popups;
for (var i = 0, popup; popup = popups[i]; i++) {
if (popup == this)
popups.splice(i, 1);
}
}
return this;
};
this.resize = function (parameters) {
this.resizing = true;
parameters = $.extend({ height: null, width: null, basedOnContent: false, load: false, urlChanged: false }, parameters);
if (!parameters.height && !parameters.width && !parameters.basedOnContent && !parameters.load)
return;
parameters.widthSupplied = parameters.width != null;
parameters.heightSupplied = parameters.height != null;
var iframeBody = this.iframe[0].contentDocument ? this.iframe[0].contentDocument.body : this.iframe[0].contentWindow.document.body,
titleH2Height = null;
if (this.titleH2)
titleH2Height = this.titleH2.outerHeight();
if ((!this.parameters.height && parameters.load) || parameters.basedOnContent) {
parameters.height = iframeBody.clientHeight;
} else if (this.parameters.height)
parameters.height = this.parameters.height;
if (parameters.heightSupplied)
this.parameters.height = parameters.height;
if (parameters.height)
this.containerDiv.animate({ height: parameters.height + (titleH2Height || 10) }, 250);
if ((!this.parameters.width && parameters.load) || parameters.basedOnContent) {
if (parameters.basedOnContent || parameters.urlChanged || (parameters.load && !this.widthResized)) {
parameters.width = iframeBody.scrollWidth - 10;
this.widthResized = true;
}
} else if (this.parameters.width)
parameters.width = this.parameters.width;
if (parameters.widthSupplied)
this.parameters.width = parameters.width;
if (parameters.width)
this.outsideContainerDiv.width(parameters.width);
this.outsideContainerDiv.height(this.containerDiv.height() + 400);
if (titleH2Height != null)
this.iframe.css("margin-top", (titleH2Height + 11).toString() + "px");
var _that = this;
window.setTimeout(function () { _that.resizing = false; }, 250);
};
this.destroy = function (parameters) {
this.hide(parameters);
ELMS.Common.unregisterPopup(this);
};
if (this.parameters.sourceElement) {
var _popup = this;
$(this.parameters.sourceElement).click(
function (event) {
var form = $("#form1")[0];
form.target = "PopupIframe";
var qs = ELMS.Common.parseQueryString(form.action);
if (typeof qs.Popup == "undefined")
form.action += (Object.keys(qs).length == 0 ? "?" : "&") + "Popup";
_popup.show();
});
}
}
var control =
{
name: "Popup",
getPopup: function (iframeOrUrl) {
for (var i = 0, popup; popup = ELMS.Common.getTopLevelWindow().ELMS.Page.Popups[i]; i++) {
if (typeof iframeOrUrl == "string") {
if (popup.parameters.url == iframeOrUrl ||
(popup.iframe && popup.iframe[0].contentWindow.location.href == iframeOrUrl))
return popup;
} else {
if (popup.iframe) {
if (popup.iframe[0] == iframeOrUrl)
return popup;
} else {
if (popup.parameters.url == iframeOrUrl.src)
return popup;
}
}
}
return null;
},
createPopup: function (parameters) {
if (parameters.width)
parameters.widthProvided = true;
parameters = $.extend({ x: 20, y: 20, showClose: false, showTitle: true, closeDestroys: true, showFooter: true }, parameters);
if (!parameters.url && !parameters.sourceElement && !parameters.sourceIframe) {
alert("parameters.url must be specified (Popup.createPopup).");
return;
}
if (parameters.showClose)
parameters.showFooter = true;
if (parameters.url) {
var qs = ELMS.Common.parseQueryString(parameters.url),
qsCount = 0;
if (!qs.Popup) {
for (var prop in qs)
if (prop != parameters.url)
qsCount++;
parameters.url += (qsCount == 0 ? "?" : "&") + "Popup";
}
}
var topWindow = ELMS.Common.getTopLevelWindow();
parameters.headerHeight = topWindow.$("#header").height();
if (parameters.headerHeight && parameters.headerHeight > parameters.y)
parameters.y = parameters.headerHeight + 50;
var popup = new ELMS.Constructs.Popup(parameters);
if (!topWindow.ELMS.Page.Popups) {
topWindow.ELMS.Page.Popups = [];
}
topWindow.ELMS.Page.Popups.push(popup);
ELMS.Common.registerPopup(popup);
if (popup.parameters.sourceIframe && popup.parameters.sourceIframe.tagName && popup.parameters.sourceIframe.tagName == "IFRAME") {
popup.iframe.css("display", "block");
popup.show();
}
return popup;
},
convertLinkToPopupWithClose: function (event, informParentOnClose) {
return ELMS.WebControls.Popup.convertLinkToPopup(event, { showClose: true, closeInformsParent: informParentOnClose | false });
},
convertLinkToPopup: function (event, parameters) {
event.preventDefault();
event.stopPropagation();
var hyperlink = $(event.target).closest("a")[0],
parameters = $.extend(
{
url: hyperlink.href,
caller: hyperlink,
event: event,
buttonSelector: ".buttons",
usesHelp: false,
title: event.target["title"]
}, parameters);
var popup = ELMS.WebControls.Popup.createPopup(parameters);
if (ELMS.Page.receivePopupMessage)
popup.addMessageCallback(ELMS.Page.receivePopupMessage);
popup.show();
return popup;
}
};
ELMS.Common.registerWebControl(control);
jQuery.fn.convertLinkToPopup = function () {
this.each(function (index, element) {
$(element).click(ELMS.WebControls.Popup.convertLinkToPopup);
});
};
jQuery.fn.convertLinkToPopupWithClose = function () {
this.each(function (index, element) {
$(element).click(ELMS.WebControls.Popup.convertLinkToPopupWithClose);
});
};
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Please do not just dump all your code and expect people to explain it to you. You have been here long enough to know the procedure.
|
|
|
|
|
Yeah I do accept my mistake but what can I do friend, its totally u-turn in technology, earlier I did javascript coding but just used some events in them getElementByID etc but this jQuery with lot of new concepts and so many things I am trying to learn it, if you can please help me.
One more thing is in the above code he is assigning function to a variable I am not sure why is he doing it all these things are big doubts.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
|
A nice tutorial to JQuery is here[^].
Click on the Classroom link, and proceed.
|
|
|
|
|
Hi All,
I am new for the jquery world, I have an unordered list in the following way in which each list item has span field, and I have another radio button in whose checked changed event I want to find which list item or span is selected using jquery.
Can I find any way to do it? Any help a link, suggestion or code snippet really helps me a lot. Please help me thanks in advance.
<ul id="reports-All_Reports" class="active"><li class="report">Child DatesDetailed date information about an individual child (for DEL only).</li><li class="report">Child DemographicsCharacteristics of children and families enrolled in ECEAP</li><li class="report">Child Record SummaryEnrollment, health, child development and family information for an individual child.</li><li class="report">Class ListLists Class names and characteristics.</li><li class="report">Class RosterLists child names, birthdate, first language, parent name and contact information, with space for staff to add notes.</li><li class="report">Class SummaryShows information entered on the Class pages of ELMS for one class, or compiled for a site, contractor or (for DEL staff) statewide.</li><li class="report">Contractor ListLists Contractor names and characteristics.</li><li class="report">Developmental ScreeningChildren's development screening dates and results.</li><li class="report">Directors RosterList of ECEAP contractors, funded ECEAP slots, directors, contact information and counties served.</li><li class="report">ELMS Site Data for Early AchieversList of all ECEAP and Head Start sites for the current school year.</li><li class="report active">Enrollment by Child<span class="description">Lists children with their age, poverty level, IEP status, priority points and first and last days attending class.
<input id="phb_rdbCurrentEnrollment" type="radio" name="ctl00$phb$ReportMode" value="rdbCurrentEnrollment" checked="checked">
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
|
var old = $.fn.carousel
$.fn.carousel = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('carousel')
, options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option)
, action = typeof option == 'string' ? option : options.slide
if (!data) $this.data('carousel', (data = new Carousel(this, options)))
if (typeof option == 'number') data.to(option)
else if (action) data[action]()
else if (options.interval) data.pause().cycle()
})
}
$.fn.carousel.defaults = {
interval: 1000
, pause: 'hover'
}
<pre lang="xml"><script>
$('.carousel-inner').carousel({
interval: 2000
})</script></pre>
I want to move slider/carousel automatically without clicking first to start
|
|
|
|
|
You'll have to look through the code for the carousel plugin and find the click event and instead change that code to run on a timer or however you want it to run.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
which carousel you are using. Can you give link for fix you need?
|
|
|
|
|
Here is what I have so far. I cant get it to work.
This application stores the last name, first name, and score for one or more students and it calculates the average score for all of the scores that have been entered.
When the user clicks on the Clear button, this application clears the score data from this application.
When the user clicks on the Sort button, this application sorts the data in alphabetical order by last name.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Student Scores</title>
<link rel="stylesheet" type="text/css" href="default.css" />
<script type="text/javascript" src="student_scores.js"></script>
</head>
<body>
<div id="content">
<h1>Student Scores</h1>
<div class="formLayout">
<label>Last Name:</label>
<input type="text" id="last_name" /><br />
<label>First Name:</label>
<input type="text" id="first_name" /><br />
<label>Score:</label>
<input type="text" id="score" /><br />
<label> </label>
<input type="button" id="add_button" value="Add Student Score" /><br />
</div>
<h2>Student Scores</h2>
<p><textarea id="scores" rows="5" cols="60"></textarea></p>
<div class="formLayout">
<label>Average score:</label>
<input type="text" id="average_score"/><br />
<label> </label>
<input type="button" id="clear_button" value="Clear Student Scores" /><br />
<label> </label>
<input type="button" id="sort_button" value="Sort By Last Name" /><br />
</div>
</body>
</html>
var scores = [];
var $ = function (id) { return document.getElementById(id) }
var displayScores = function () {
var scoreNumber = parseInt( $("score").value );
var scoreString = $("last_name").value + ", " +
$("first_name").value + ": " +
$("score").value;
if (scoreSting.length == 0) {
for (var i = 0; i < displayScores.length; i++) {
var scores = displayScores[i];
for (var i in scores) { displayScores += scores[scoreString] + ", "; }
$("average_score").value = getAverageScore(scoreNumber);
}
var addScore = function () {
var scoreNumber = parseInt( $("score").value );
var scoreString = $("last_name").value + ", " +
$("first_name").value + ": " +
$("score").value;
scores.push(scoreNumber);
scoresString.push(scoreString);
displayScores();
}
var getAverageScore = function () {
var scoreNumber = score.length;
var sum = 0;
if (scoreNumber > 0) {
for (var i = 0; i in scoreNumber; i++)
sum += score[i][2];
}
$("average_Score").value = sum / scoreNumber;
}
var sortScores = function () {
scoresString.sort();
displayScores();
}
}
window.onload = function() {
$("add_button").onclick = add_button;
$("sort_button").onclick = sort_button;
}
modified 17-Feb-15 18:14pm.
|
|
|
|
|
WebDesignStudent wrote: I cant get it to work.
is not enough information. What is it doing? What is it supposed to do? Please edit the question to add detail and context.
|
|
|
|
|
Do not post it as a reply! Edit the question and add it there!
|
|
|
|
|
How should I start learning javascript. From where should it, Any book, Video tutorial etc. I just have 3 months and want to learn javascript to basic or intermediate level not advanced level in 3 months. Please guide me
|
|
|
|
|
|
One really nice tutorial I found is here[^].
Click on the Classroom link, and get going.
|
|
|
|
|
3 months are fair enough to learn JavaScript. First learn some basic concepts of JavaScript like how to manipulate DOM, Event binding, functions in JavaScript.I will suggest learn some jQuery for DOM manipulation. After this start creating some small Application like calculator.Gradually you will understand how things works in JavaScript.
After that you can try some books like JavaScript good part.
|
|
|
|
|
I recommend "learning by doing", which, in your case, means not reading lots of text about the intricacies of the language (like in most JS programming books), but rather read the minimum necessary to start programming your first app. This approach is implemented in my tutorial book Engineering Front-End Web Apps with Plain JavaScript.
|
|
|
|
|
You can start with 'Object-Oriented javascript by Stoyan Stefanov'. Very simple language and start from basics. A must have book for any javascript programmer.
Prateek
|
|
|
|
|
|
I am brand new to coding of any kind. I am reading W3schools, Javascript String Methods, and one of the functions I don't understand is what is the function/purpose of Extracting String Characters?
These two codes are particularly unclear to me charAt() and charCodeAt(). When would they be used?
|
|
|
|
|
Member 11446034 wrote: charAt() and charCodeAt()
The charAt function[^] returns the character at the specified index. For example, if the string contains "Hello", s.charAt(0) will return "H" .
The charCodeAt function[^] returns the numeric Unicode value of the character at the given index. For example, if the string contains "Hello", s.charCodeAt(0) will return 72 , which is the Unicode value that represents an uppercase "H".
List of Unicode characters[^]
Member 11446034 wrote: When would they be used?
They would be used when you need to extract either a character, or the Unicode value of a character, at a particular index in a string.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
good information.
|
|
|
|
|