|
ghazabaz wrote:
window.onload = init();
...
calcButtons[i].onclick = buttonClick();
...
document.getElementById("calcWindow").addEventListener(onkeydown, calcKeys());
Those are likely candidates for your error. You're setting the event handler to the value returned from calling the function with no parameters, rather than the function itself.
When you call buttonClick with no parameters, e will be undefined , and you will get your error.
Remove the parentheses from the event handlers. You should probably use addEventListener consistently as well.
window.addEventListener("load", init);
...
calcButtons[i].addEventListener("click", buttonClick);
...
document.getElementById("calcWindow").addEventListener("keydown", calcKeys);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Both Richards, thanks a bunch.
After making changes to the function parentheses, the enter, delete and backspace of the calculator are now fully functional. However, none of the digits are keying in when clicked on the webpage?
Works fine if entered through the keyboard however. I am guessing it has something to do with:
for (var i = 0; i < calcButtons.length; i++) {
calcButtons[i].addEventListener("click", buttonClick);
}
document.getElementById("calcWindow").addEventListener("keydown", calcKeys);
}
OR
function buttonClick(e) {
var calcValue = document.getElementById("calcWindow").value;
var calcDecimal = document.getElementById("decimals").value;
var buttonValue = e.target.value;
switch(buttonValue) {
case "del":
calcValue = "";
break;
case "bksp":
calcValue = eraseChar(calcValue);
break;
case "enter":
calcValue = " = " + evalEq(calcValue, calcDecimal) + "\n";
break;
case "prev":
calcValue = + lastEq(calcValue) ;
calcValue = calcValue + buttonValue;
break;
}
document.getElementById("calcWindow").value = calcValue;
document.getElementById("calcWindow").focus();
}
Actually getting an error on:
calcValue = + lastEq(calcValue); which handles the previous button. But my main focus now are the number digits of the calculator.
|
|
|
|
|
ghazabaz wrote: calcValue = + lastEq(calcValue) ;
You're missing an operand there. It should look like one of these:
calcValue = SOMETHING + lastEq(calcValue);
calcValue += lastEq(calcValue);
calcValue = lastEq(calcValue);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Assuming your number buttons are in the calcButtons array, you'll need a default case in your switch statement to handle them:
switch (buttonValue) {
...
case "prev":
calcValue = ??? + lastEq(calcValue) ;
calcValue = calcValue + buttonValue;
break;
default:
calcValue = calcValue + buttonValue;
break;
}
JavaScript Switch Statement[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard, thank you very much.
After implementing the suggested corrections (added "append" operator to line 95 in mt_calc.js file) the buttons are functional except the "previous" calculator buttons. Also, enter, delete and up arrow (supposed to copy & yield previous equation) are not working when used on keyboard.
Also getting a "NaN" along with the answer?
These are the instructions for the enter, delete and up up arrow buttons:
Quote: . Click within the calculator window and, using the keyboard, directly type a mathematical expression. Verify that pressing the Enter key evaluates the current expression and moves the cursor to a new line. Show that you can copy the previous expression by pressing the Enter key followed by the up-arrow key on your keyboard. Finally verify that pressing the Delete key clears the contents of the calculator window. Note: Keyboard commands might not work in the Safari browser since Safari does not support the key property at the time of this writing.
I added the append operator to calcValue = calcValue + buttonValue; as the instructions require:
Quote: Otherwise, append the calculator button character to the calculator window by letting, calcValue equal calcValue plus buttonValu
But when a calculator digit is entered and entered again it multiplies itself infinitely.
I was hinted at these sections as the answer:
switch(buttonValue) {
case "del":
calcValue = "";
break;
case "bksp":
calcValue = eraseChar(calcValue);
break;
case "enter":
calcValue = + " = " + evalEq(calcValue, calcDecimal);
break;
case "prev":
calcValue = lastEq(calcValue);
default:
calcValue = calcValue + buttonValue;
break;
}
switch(e) {
case "Delete":
calcValue = "";
break;
case "Enter":
calcValue = + " = " + evalEq(calcValue, calcDecimal);
break;
case "ArrowUp":
calcValue += lastEq(calcWindow.value);
break;
case "ArrowUp":
e.preventDefault();
break;
}
Here is the entire code for reference:
"use strict";
window.addEventListener("load", init);
function init() {
var calcButtons = document.getElementsByClassName("calcButton");
for (var i = 0; i < calcButtons.length; i++) {
calcButtons[i].addEventListener("click", buttonClick);
}
document.getElementById("calcWindow").addEventListener("keydown", calcKeys);
}
function buttonClick(e) {
var calcValue = document.getElementById("calcWindow").value;
var calcDecimal = document.getElementById("decimals").value;
var buttonValue = e.target.value;
switch(buttonValue) {
case "del":
calcValue = "";
break;
case "bksp":
calcValue = eraseChar(calcValue);
break;
case "enter":
calcValue = + " = " + evalEq(calcValue, calcDecimal) + "\n";
break;
case "prev":
calcValue = lastEq(calcValue);
default:
calcValue = calcValue + buttonValue;
break;
}
document.getElementById("calcWindow").value = calcValue;
document.getElementById("calcWindow").focus();
}
function calcKeys(e) {
var calcValue = document.getElementById("calcWindow").value;
var calcDecimal = document.getElementById("decimals").value;
switch(e) {
case "Delete":
calcValue = "";
break;
case "Enter":
calcValue = + " = " + evalEq(calcValue, calcDecimal);
break;
case "ArrowUp":
calcValue += lastEq(calcWindow.value) ;
break;
case "ArrowUp":
e.preventDefault();
break;
}
document.getElementById("calcWindow").value = calcValue;
}
function eraseChar(textStr) {
return textStr.substr(0, textStr.length - 1);
}
function evalEq(textStr, decimals) {
var lines = textStr.split(/\r?\n/);
var lastLine = lines[lines.length-1];
var eqValue = eval(lastLine);
return eqValue.toFixed(decimals);
}
function lastEq(textStr) {
var lines = textStr.split(/\r?\n/);
var lastExp = lines[lines.length-2];
return lastExp.substr(0, lastExp.indexOf("=")).trim();
}
|
|
|
|
|
ghazabaz wrote:
calcValue = + " = " + evalEq(calcValue, calcDecimal) + "\n";
You're still missing an operand there.
calcValue = ??? What goes here ??? + " = " + ...
ghazabaz wrote:
case "prev":
calcValue = lastEq(calcValue);
default:
You're missing a break; statement in that switch case, so control "falls through" to the default case.
JavaScript Switch Statement[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard. You are right, I was missing the operands and a break statement. I managed to fix it by Sunday evening. Really appreciate the help !
|
|
|
|
|
Hi,
I am looking for free HTML Page Design Software to create a Simple Web Page, in which I can edit the HTML Code manually to customise.
Any Ideas?
Bram.
Bram van Kampen
|
|
|
|
|
Notepad
Better yet:
Notepad++
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
use
Visual studio code
or
Visual studio community edition
=====================================================
The grass is always greener on the other side of the fence
|
|
|
|
|
Firefox has visual access to page content. Very robust editing of HTML via Web Developer/Inspector.
I've been using Firefox as a go-to internet browser for several years now and only recently have begun using it to do things that only Visual Studio has been able to do before it's discovery.
|
|
|
|
|
Hi,
That seems a reasonable suggestion.
I'll try and Download Firefox, and see how it goes.
Thanks.
Bram van Kampen
|
|
|
|
|
Hi!!
so, I have this Ajax function vinculated to a change Jquery event:
$("#nif").change(function(){
<pre> $.ajax({
async:true,
type:"POST",
data:N,
url:"<?=$this->basePath("alta/nuevouser/vernifduplicadoajax")?>",
success:function(datos){
$("#res").html(datos);
}
});
});
The matter is...that the result is or "1" (double register at DB) or "0" (no repeat), the value always appear in the div, depending of this result, I want to activate another and show a message an other operations..
to evaluate this value I do the next
if($("#res").length !==0){
var warn=parseInt(document.getElementById("res").innerHTML);
alert(warn);
}
but I always receive (using alert();)..isNan ...that is, "is not a Number"..
I`d need to evaluate:
if(warn==1){
//do this
}else{
//do that
}
Thanks a lot in advance!!
|
|
|
|
|
All that means is that document.getElementById("res").innerHTML does not contain a number. All you have to do is put a breakpoint there, run the code, and see what the value is and you'll figure out what is going on.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I have some sort of similar markup as shown in last.
I want to filter the inner text elements based upon ids innerfilter1, innerfilter2.
I have also written code for hide general content based upon the outer filter. i.e. myid1 and myid2 which works fine. Here ids will hide divs have same classes
$('ul.nav.nav-tabs>li>a').click(function(){
var curtab = $(this).attr('href').substring(1);
console.log(curtab);
$('.tab-content .tab-pane').each(function(){
var tabid = this.className;
if(tabid.indexOf(curtab) > -1){
$(this).siblings().hide();
}
});
$(this).show();
});
});
But nested filters use to filter the content which is not general but having filter either innerfilter1, innerfilter2. I have tried below code but this effects other tabs as well also impact
$('div.inner-tab-box>ul.nav.nav-tabs>li>a').click(function(){
var curtab = $(this).attr('href').substring(1);
$('.tab-content .tab-pane').each(function(){
var tabid = this.id;
if(tabid.indexOf(curtab) > -1){
$(this).siblings().each( function () {
var tx=this.id;
if(tx==='general') {
} else {
$(this).hide();
}
});
$(this).show();
}
});
});
Full Markup
<div class="top-header">
<div class="container-fluid">
<div class="header-top">
<!-- Tabs -->
<div id="tabs">
<!-- tabs start -->
<div class="tab-content">
<!-- part 1 Will execute 2 times as per filters-->
<div role="tabpanel" class="tab-pane active" id="myid1">
<div class="row">
<div class="col-xs-5ths ">
<div class="dark-box-outer">
<div class="top-light-text-box">
<div class="inner-tab-box ">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class=""><a href="#innerfilter1" aria-controls="home" role="tab" data-toggle="tab">></a></li>
<li role="presentation" class=""><a href="#innerfilter2" aria-controls="profile" role="tab" data-toggle="tab"></a></li>
</ul>
[B]<div class="tab-content">
<div role="tabpanel" class="tab-pane myid1 " id="innerfilter1">
<ul>
<li>
</li>
</ul>
</div>
<div role="tabpanel" class="tab-pane myid1 " id="innerfilter2">
<ul>
<li>
</li>
</ul>
</div>
<div role="tabpanel" class="tab-pane myid1 " id="general">
<ul>
<li>
</li>
</ul>
</div>
<div role="tabpanel" class="tab-pane myId2 " id="general">
<ul>
<li>
</li>
</ul>
</div>[/B]
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-5ths ">
<!-- Repeated Markup -->
</div>
<div class="col-xs-5ths ">
<!-- Repeated Markup -->
</div>
<div class="col-xs-5ths ">
<!-- Repeated Markup -->
</div>
<div class="col-xs-5ths ">
</div>
</div>
</div>
<!-- end part 1 -->
<div role="tabpanel" class="tab-pane " id="myId2">
<!--Repeated Content For myId2-->
</div>
<!-- end part 1 -->
</div>
<!-- End part 2 -->
</div>
</div>
<!-- ./Tabs -->
</div>
</div>
Can anyone help me to fix this.
Thanks
|
|
|
|
|
I do not understand what your question is. Maybe you can provide a simple summary and ask a clear question.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Hey guys I need some final help with this code. Nothing is showing on the page. Thanks
"use strict";
var gameReport = "<h1>" + itemTitle + "</h1>" +
"<h2>By:" + itemManufacturer + "</h2>" +
"<img src= 'hg_" + itemID + ".png' alt='" + itemID + "' id= 'gameImg' />" +
"<table>" +
"<tr><th>Product ID</th><td>" + itemID + "</td></tr>" +
"<tr><th>List Price</th><td>" + itemPrice + "</td></tr>" +
"<tr>Platform</th><td>" + itemPlatform + "</td></tr>" +
"<tr><th>ESRB Rating</th><td>" + itemESRB + "</td></tr>" +
"<tr><th>Condition</th><td>" + itemCondition + "</td></tr>" +
"<tr><th>Release</th><td>" + itemRelease + "</td></tr>" +
"</table>" ;
itemSummary;
document.getElementByTagName("article")[0].innerHTML = gameReport;
var ratingSum = 0;
var ratingsCount = ratings.length;
for (var i = 0; i < ratings.length; i++) {
ratingSum = ratingsCount + ratingSum;
}
var ratingsAvg = ratingSum / ratingsCount;
var ratingReport = "<h1>Customer Reviews</h1> <h2> " + ratingsAvg + "out of 5 stars (" + ratingsCount + "reviews) </h2>";
for (var i = 0; i <= 2; i++) {
ratingReport += "<div class=review><h1>" + ratingTitles + "</h1><table><tr><th>By</th><td>" + ratingAuthors + "</td></tr><tr><th>Review Date</th><td>" +ratingDate+ "</td></tr>" "<tr><th>Rating</th><td>";
for (var i = 1; i < ratingsAvg.length; i++) {
ratingReport += '<img src="'+ hg_star.png + '"/>';
}
ratingReport += "</td></tr</table>" + ratingSummaries + "</div>";
}
document.getElementByTagName("aside")[0].innerHTML = ratingReport;
Thanks
modified 1-Dec-18 21:22pm.
|
|
|
|
|
This is very easy to fix. Put a breakpoint in the code, then run it, and see what is happening. Then you can fix it.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
hi
I think the problem is your 'for' loop variable names. as you see the first and second 'for' loop variable is "i", change the second one to some thing like "j" an have a try
|
|
|
|
|
My Question is: - How to Pass two dimensional array in javascript from view to controller in mvc when row is 2 but coloumn is n number(coloumn dynamically can be increase).
|
|
|
|
|
You have several steps you need to do. Where exactly are you stuck?
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Hey guys,
I need assistance with 2 blocks of code that I am getting error. Here they are:
var gameReport = "<h1>" + itemTitle + "</h1>" +
"<h2>By:" + itemManufacturer + "</h2>" +
"<img src="hg_id.png" alt="id" id=" + gameImg + " />" +
"<table>"
"<tr><th>Product ID</th><td>" + itemID + "</td></tr>" +
"<tr><th>List Price</th><td>" + itemPrice + "</td></tr>" +
"<tr>Platform</th><td>" + itemPlatform + "</td></tr>" +
"<tr><th>ESRB Rating</th><td>" + itemESRB + "</td></tr>" +
"<tr><th>Condition</th><td>" + itemCondition + "</td></tr>" +
"<tr><th>Release</th><td>" + itemRelease + "</td></tr>" +
"</table>" +
itemSummary;
And this:
for (var i = 0; i < 3; i++) {
ratingReport += "<div class="review"><h1>" + ratingTitles + "</h1><table><tr><th>By</th><td>" + ratingAuthors + "</td></tr><tr><th>Review Date</th><td>" +ratingDate+ "</td></tr>""<tr><th>Rating</th><td>";
for (var i = 1; i < ratingsAvg.length; i++) {
ratingReport += "<img src="hg_star.png" />";
}
ratingReport += "</td></tr</table>" + ratingSummaries + "</div>";
}
Thanks for any help
|
|
|
|
|
The syntax highlighting should have given you a clue - you need to escape quotes inside the string or use single quotes as well as double quotes.
var escaped = "<img src=\"an_image.png\">";
var single_quotes = '<img src="another_image.png">';
You should also check that you have your "+" symbols everywhere you need them - there is one missing after the opening <table> element.
|
|
|
|
|
"<img src="hg_id.png" alt="id" id=" + gameImg + " />" +
IF you are using for loop id need to unique value
|
|
|
|
|
Hallo!
I have a textbox , (made with Zendform), and y load the results of an array in this textbox with the autocomplete();
function , this was performing as expected a few days ago, but today the result is disgusting..the results appear by the textbox this way:
.Galicia
.Asturias
.[...]
this function its asociated with a"keyup" event...please any idea of what could be wrong??, I executed in Chrome, and the compilator, shows no errors... thanks!!
so let´s go to the code
$(document).ready(function(){
var comunidades=[
"Galicia",
"Asturias",
"Cantabria",
"Islas Baleares"
];
<pre> $("#comu").keyup(function(){
$(this).autocomplete({
source:comunidades
});
});
</pre>
<pre>
<label>Comunidad</label>
<?php
$fComu=$formNewClienteHotel->get("comunidad");
echo $this->formInput($fComu);
?>
</pre>
This is the class where the Form is declared:
<?php
namespace Alta\Form;
use Zend\Form\Form;
use Zend\Form\Factory;
use Zend\Form\Element;
class FormNewClienteHotel extends Form
{
public function __construct($name=null) {
parent::__construct($name);
$this->setAttributes(array(
'action'=>'',
'method'=>'post'
));
$this->add(array(
'name'=>'comunidad',
'attributes'=>array(
'type'=>'text',
'required'=>'required',
'id'=>'comu',
)
));
|
|
|
|