VirtualMV/JavaScript/HelpDesk - Interactive

From WikiEducator
Jump to: navigation, search




Overview

This page can be used in a group situation to discuss problems that can occur when coding. The problem is presented and after discussion a potential solution can be revealed.

Instructions

On this page you can post some JavaScript code that you are having trouble with.

  • Please keep the code "simple" concentrating on the problem ... not a lot of code with a "small" problem.
  • Post a tweet including the #vmvwiki tag so that we know there is a problem waiting to be solved.
  • Paste the following wiki code when you edit, and put your code where shown.

{{vmv:Source|<source lang="javascript">
Code in here
</source>}}

Problem 14: Checking a number has been entered

This is actually quite tricky but here is a solution

Problem 13: getElementById and innerHTML returns an error

You have entered the following code

document.getElementByID("test").innerHTML = "TestData";

and it returns

Error message: File.html:13 Uncaught TypeError: document.getElementByID is not a function

Problem 12: Opening a window and creating the hml file in js gives a blank window

In your JavaScript you have

	winMsg=window.open("","_blank");
	winMsg.document.write("<html><head><title>Hire Summary<title>");
	winMsg.document.write("</head>");
	winMsg.document.write("<body>");
	winMsg.document.write("<h2>Hire Summary<h2>");
	winMsg.document.write("</body></html>");

Problem 11: changing code has noeffect

In your JavaScript you have

 

and even changing the code has no effect.

Problem 10: an input field won't accept background style

In the HTML you have entered the following code

<input type="text" id="nameLastFirst" name="nameLastFirst" maxlength="30">

In your JavaScript you have

var name = document.getElementById("nameLastFirst"); 
name.style.backgroundColor = "yellow";

and it returns and undefined error.

Problem 9: Trying to change the innerHTML of an element returns an error

You have entered the following code

<head>
<script>
    document.getElementById("idBusiness").innerHTML = "my business name";
</script>
</head>
<body>
<h1 id="idBusiness">??</h1>
</body>

and it returns and undefined error.

Problem 8: When you click Add row to a table, the row is added, the screen flashes and the row disappears

You have entered the following code

<form name="frmStuff" >
  <p>Description<input id="txtdesc" type="text" value=""/></p>
  <p><input type="submit" value="Add Row to table" onClick="fnaddToTable()"></p> 
  <table id= "bookingTable" border="1">
  <tr><th>Type</th><th>Description</th></tr>
  </table> 
</form>

and When you click Add row to Table, the row is added, the screen flashes and the row disappears.

Problem 7: A getElementbyID doesn't work

You have entered the following code

<html>
<head>
<script type="text/javascript">
  function displayResult() {
    alert( "Name is " + document.getElementById("txtFName").value);
    }
  </script>
</head>
<body>
<form name="myForm">
   <p>Enter Your Fullname:<input type="text" name="txtFName" value="" /></p> 
  <p><button type="button" onclick="displayResult()">Display Name</button></p>
</form>  
</body>
</html>

and it doesn't work.


Problem 6: A window open causes a JavaScript error

You have entered the following code

winMsg=window.open("","Display Window","scrollbars=yes, resizable=yes");

and it doesn't work.

Problem 5: Adding two numbers js file

one.html

<html>
<head>
<title>Add two numbers</title>
<script type="text/javascript">
  function fnCalcTotal() {
    vntAmount1=frmAdd.txtAmount1.value;
    vntAmount2=frmAdd.txtAmount2.value;
    document.frmAdd.txtTotal.value = (parseFloat(vntAmount1) + parseFloat(vntAmount2));  }
</script>
</head>
<body>
<form name="frmAdd">
  <p>With these two numbers:<br /> 
  Number 1<input name="txtAmount1" type="text" value="$100" /><br />
  Number 2<input name="txtAmount2" type="text" value="$200" /></p>
  <p><input type="button" name="Submit" value="Calculate total" onClick="fnCalcTotal()" /></p>
  <p><input name="txtTotal" type="text" value="" /></p>
</form>
</body>
</html>

When Calculate button clicked - Error: Line 8, Character 5, Object expected

Problem 4: Linked js file

one.html

<html>
  <head></head>
  <body>
    <script type="text/javascript" src="one.js"></script>  </body>
</html>

one.js

<script type="text/javascript">
  document.write("This script is external");
</script>


Problem 3: Comments

<html>
<head></head>
<body>
<div style="color: #0000FF">
<script type="text/javascript"><!-- document.write('<h1>Hello world.. JavaScript rulz!</h1>') //--></script></div></body></html>


Problem 2: variables

<html>
<body>
<script type="text/javascript">
  var intA = 3;
  var intSum = inta + 5;
  document.write("Adding 5 to intA is " + intSum +"<br />");
</script>
<p>This example 5 is added to a variable.</p>
</body>
</html>


Problem 1: variables

<html>
<body>
<script type="text/javascript">
  var intA = 3;
  int intB = 5;
  var intSum = intA + intB;
  document.write("The sum of 3 and 5 is " + intSum +"<br />");
</script>
<p>This example shows the sum of two numbers.</p>
</body>
</html>


VmvIcon References.png References

virtualMV  |  Superquick wiki guide  |  Please give me some feedback

VirtualMV/JavaScript/HelpDesk - Interactive. (2024). In WikiEducator/VirtualMV wiki. Retrieved November 5, 2024, from http:https://wikieducator.org/VirtualMV/JavaScript/HelpDesk_-_Interactive    (zotero)