The Technology2Reality Blog Feed

 
 

Question by dots: Why my javascript code not working?



Instructions:

Answer the three questions and press go.
Your score will appear.

Input values:

1. A byte is how many bits
2. Steve Jobs heads what company?
3. Bill Gates heads what company?

Output value:

Result #1:
Result #2:
Result #3:
Your score:


Best answer:

Answer by Dominic H
It’s tough deciding on where to start.

First, you need to end your expressions with semicolons. I know that they get entered automatically but the automatic function sometimes does it wrong and it ends up breaking your script in ways not easy to find. So follow JavaScript best practices and always end an expression with a semicolon.

This:

var firstName;
firstName = “John”;

Not this:

var firstName
firstName = “John”

You can also save yourself some typing by declaring your variable and settings its value at the same time.

var Counter = 20;
var firstName = document.getElementById(“first-name”);

Next, you declare your variables at the top of your function. That’s a great practice but later in your code you add four more variables that weren’t defined with var. Can you see them? Here’s the list.

myResult1
myResult2
myResult3
score

JavaScript is case sensitive so Score and score are two different objects as far as JavaScript is concerned.

Your script is missing a closing curly brace at the end of your function.

In your if blocks you do:

if (myAnswer2.toLowerCase() == “Apple”.toLowerCase()) { … }

You can simplify it to this:

if (myAnswer2.toLowerCase() === “apple”) { … }

You can just write the word apple in lower case instead of calling a function to do it. Also use the === operator when comparing values.

You never use the Result1, Result2, and Result3 variables after you set them to hold HTML elements.

Also, Bill Gates is not the head of Google but I’m pretty sure you know that and are just using it to get a wrong answer message. I still had to mention it in just in case I’m wrong.

Add your own answer in the comments!

Tagged with:
 

Javascript Saturday

Javascript Saturday
Event on 2012-11-10 09:00:00

Javascript Saturday is a complete one-day Training from the best of the Javascript experts aimed at all levels of expertise. 

Have no experience in Javascript? – Go from beginner to advanced in a day.

Want to know about Javascript frameworks and how to advance in your career – This event is for you.

Victim of Information overload? – You will know what you need to know and you will find out what you don't know.

RockStar Speakers 

Nathan Totten – Microsoft

Nathan Totten is a Technical Evangelist at Microsoft specializing in Windows Azure, web development, and Node.js. He is also the creator and lead developer of the Facebook C# SDK (http://csharpsdk.org). Before Microsoft, Nathan was a Senior Software Engineer at a startup where he worked on social media applications and analytics tools. He has experience building Windows Azure applications that handle large traffic spikes and maintain high availability and performance. He is also actively involved in open source development and the developer community. You will regularly find him answering questions on Stackoverflow.com or open source forum discussions.

Chander Dhall – INETA speaker, Microsoft MVP

Chander Dhall is a Microsoft MVP, author, trainer, mentor, professional software architect/lead developer, INETA speaker, open source contributor, community leader and organizer with years of experience in enterprise Software Development. He works in a goal oriented, technologically driven, fast paced AGILE (SCRUM) environment. He is the founder of Dallas day of dot net. He has a Master’s Degree in computer science with specialization in algorithms, principles and patterns and is focused on building high performing modular software. Chander leads the UT Dallas .NET user group. Chander recently got recognized as "One of the top organizers by Eventbrite. Chander has been a featured speaker in numerous conferences and code camps all over the world. You may follow him on twitter @csdhall.

Agenda (First 30 attendees can only vote to change the agenda)

1. Introduction to Javascript

2. Introduction to Jquery

3. Knockout JS

4. HTML5/CSS – Responsive web design

5. Intro to Nodejs

6. Javascript Patterns

7. Socket IO vs Signal R

8. Javascript Best practices

RockStars contd…

Hattan Shobokshi

Hattan Shobokshi is a Microsoft Community Contributor, Speaker & Senior Software Engineer. Hattan is responsible for developing applications on a variety of platforms including web and mobile devices. He is a passionate software architect that is focused on delivering scalable applications that adhere to industry best practices. Hattan is experienced in .NET technologies, with a particular expertise in ASP.NET MVC & web technologies. He regularly presents at local user groups and code camps. Hattan is an avid JavaScript developer and is experienced in building rich client side user interfaces using JavaScript and its supporting technologies.You can get more information about Hattan from his website at http://www.hattanshobokshi.com .

Jeff Carlos Co-founder/CTO Triplark.com

Jess Carlos is a Software D eveloper and Entrepreneur residing in San Diego, CA. He has 13 years of software development experience spending most of his time working at Sony Electronics, Inc. planning, developing and deploying enterprise level applications before moving onto Triplark.com. At Triplark he is responsible for refining the core product offering and planning the overall technical strategy for the company. In 2012 he co-founded JavaScriptU in San Diego, CA which aims to develop communities by teaching leading-edge JavaScript frameworks and techniques. He is a proponent of Open Source Software development contributing many of his own projects to open source and working on to many other open source projects over the years. He is a very enthusiastic and passionate teacher who enjoys working with fellow software developers at various levels. You can find out more information about Jess by visiting his website jesscarlos.com or following him on twitter @jesscarlos.

Troy Miles

A designer and developer of software since 1979, Troy began his career writing games in assembly and C. Since then he has written code in C++, C#, Objective-C, Java, JavaScript and even a smidgen of Python. Along the way, some of his titles have won awards, he became a Microsoft Certified Solution Developer, and in 2012, he won a developer challenge at a local Microsoft Windows Phone Unleashed event.

His passion since 2007 has been mobile and mobile web development. In 2011, he joined the mobile development team at Kelley Blue Book. His small team is responsible for the KBB.com application for iPhone, Android, and Windows Phone 7 and the mobile versions of KBB.com. Troy also spends time talking to developer groups and maintaining his blog, The Rock n Coder.

Jason Beres

Jason Beres, VP of Product Management, Community, and Developer Evangelism

As the Vice President of Product Management, Community, and Evangelism, Jason spearheads customer-driven, innovative features and functionality throughout all of Infragistics' products. Mr. Beres is a Microsoft .NET MVP, on the INETA Speakers Bureau, and the author of multiple books on various .NET technologies, the latest being Silverlight 4 Professional from Wrox Press.

at Long Beach Convention and Entertainment Center
300 E Ocean Blvd,
Long Beach, United States

Tagged with:
 

Question by : im trying to display xml file in browser with this javascript code. the xml file is on my desktop.?



Best answer:

Answer by ❛⓬ Ѕטϻϻᴇʀ Ѕɵᴌᵴтιɕᴇ ☀ ≡ ℛᴬᴳᴳᴵᵁᴻᵀᴼ 1.00⁵ ₧
Sort in descending order instead of:
document.write(“

“);
var x=xmlDoc.getElementsByTagName(“contact”)…
for (i=0;i {
document.write("
“);

Know better? Leave your own answer in the comments!

Tagged with:
 

Question by : Why won’t this javascript webpage work?
Ok, so i’m currently learning how to write web pages using JavaScript and HTML. I’ve been asked to create a page that uses forms and functions.
Bascially in this page the user inputs personal information and when the “Show Details” button is clicked, a new window should open up displaying that information. But that’s not happening.



Form Input

Please enter your details in the form below


Name:

Phone Number:

E-Mail:




I changed it to ShowWindow=window.open(“”,”window1″,’

And also changed the capital letter on =Showdetails

I don’t know why the dimensions line didn’t show up on the post but it was there on my script…

And it works!, thanks for the answers.

Best answer:

Answer by Emily
i THINK i see some problems but i’m not sure. i haven’t messed with html or javascript since the beginning of last summer. which is odd for me. Anyways. I’ll try to figure it out but make sure this works without the form first. Like try to do everything seperatly. I remember when i used to use javascript and i never actually needed the form thing. Or do everything seperatly then work your way up from there. Like make one input box and button then add another input box. Search around w3schools.com a little. Thats what i do when i forget stuff

Give your answer to this question below!

Tagged with:
 

Question by : Problem with Javascript Execution in IE only (fine in Chrome/FF)?
Here’s the code. I cannot edit all the content of the site, so the code gives all TR tags and all INPUT tags an id attribute set inside a for loop so i can then edit specific TR and INPUT tags via getElementById.

It works flawlessly in Chrome/Firefox, without throwing warnings or errors, but won’t even execute in IE.

http://browsehomesales.com/gold_distress.asp

My javascript code:


I agree, the code isn't ideal. However, the website is one of those done-for-you (how wonderful) deals.

The Syntax error applies to the Google Analytics code, I believe (ga.js), not to the code I've written, which I've posted above. I edited the code on the site to give IDs that start with a letter (i.e. "tr80" and "input80"). Code still not working in Internet Explorer.

Best answer:

Answer by jimbot
IE pops the following error on that page

Message: Syntax error
Line: 1
Char: 1
Code: 0
URI: http://www.discovershortsales.com/scripts/ga.js

A couple of things:
1 - ID attributes must begin with a LETTER. So having is invalid. Might still work anyway, but no guarantees.
2 - Your method of "getting all the elements, then assigning ids to them, then operating on a few of them based on the id" is a bit nasty. You'd be better off to structure the page in such a way that you can easily get only the elements you want to operate upon. Also, if you need to insert more elements between existing ones, you won't have to redo all of the code. If you can enclose the elements you want to work on in a div or something you can easily locate that div, then get all the "inputs" in it.

eg


...

var onesIWant = document.getElementById('myInputs' ).getElementsByTagName('input' );
will give you an array containing only something2 and something3

Know better? Leave your own answer in the comments!

Tagged with:
 

Question by : Problem with Javascript in IE. I HATE INTERNET EXPLORER?
Here’s the code. I cannot edit all the content of the site, so the code gives all TR tags and all INPUT tags an id attribute set inside a for loop so i can then edit specific TR and INPUT tags via getElementById.

It works flawlessly in Chrome/Firefox, without throwing warnings or errors, but won’t even execute in IE.

http://browsehomesales.com/gold_distress.asp

My javascript code:


Oh believe me, if I could just ignore IE in developing websites, I would. Unfortunately, the majority of visitors still use IE, so I must continue to develop for it. So if anyone can figure out why the code executes flawlessly in Chrome/Firefox, yet won't even run in IE, please help me out on this one.

Best answer:

Answer by lithiumMGO
use mozilla firefox its 10 time better download it at --->

http://www.mozilla.com

Know better? Leave your own answer in the comments!

Tagged with:
 

Question by Devilz Wishbone: Calling a Javascript function from PHP?
I got a contact us page at the moment on my website
Naturally this uses PHP, There are 4 methods of contact

Phone
Postal
Live Chat
Email

The user can click on which method they wish to use on the page its self and using a javascript / ajaxing method the tables will expand or contract depending on the option the viewer selected.

I have also added a Windows Vista style menu where the user can click contact us (A drop down menu appears with the 4 methods of contact)

When the user click on one (lets say Email)

The URL becomes…

index.php?page=contact&method=email
(As the headers/page design remain the same only the content alters)

I have captured the method on the contact.php
But when I tell it to write into the page

It does action it

The outcome is as i intended it to be on the HTML source code

But it wont do anything, yet if you click on the images it will do it using HREF=”Javascript:linktwo();”

Best answer:

Answer by Manu
Hey,

That’s a nice question! well to be frank thats what I was trying to do to a call a JS function from PHP but every time it makes me feel like PHP cannot interact with JS cos..

Since PHP is server side and is already parsed from server and JS is client side so PHP execution occurs first.

That what all i know.

Visit this site and perhaps, you can find your solution that where i find my of my solutions. It’s a nice site

TUT : http://aea.ueuo.com/tt/php/phpt.php
CODE: http://aea.ueuo.com/src.php
Thanks

Add your own answer in the comments!

Tagged with:
 

Question by Robert B: Javascript or flash player problems?
some websites that use javascripts and flash player dont work, like newgrounds for example, when i go to a game or a video and click “watch” or “play”, nothing pops up. my cookies are enabled, jacascript is enabled, and so is flash player and they are both up to date. yet, youtube works and google video works. what the heck is going on?

Best answer:

Answer by danielcc
if your cookies, java, flash, activex, and browser are up to date and enabled then you know its not on your end and thus is on the websites end. give them a week to update and catch up and things might start working again…

Give your answer to this question below!

Tagged with: