EvilZone
Programming and Scripting => Web Oriented Coding => : Dijkstra February 07, 2015, 02:47:28 PM
-
I am not sure what I am doing wrong. I have a simple HTML file that points to a javascript function.
HTML
--------------------
<!DOCTYPE html>
<html>
<head>
<title>Javascript Test</title>
<script type="text/javascript" src="Test.js"></script>
</head>
<body>
<input type="text" name="txtFirstName" id="txtFirstName" placeholder="First Name" />
<br />
<br />
<input type="text" name="txtLastName" id="txtLastName" placeholder="Last Name" />
<br />
<br />
<button onclick="CombineName();">Click Me</button>
</body>
</html>
JS file is: Test.js
--------------------------
function CombineName()
{
var FirstName = document.getElementByld("txtFirstName").innerText;
var LastName = document.getElementByld('txtLastName')/innerText;
CombineName5 = txtFirstName + txtLastName;
alert(CombineName5);
}
------------------------------------
I cannot get my browser to show me an alert. Any thoughts as to why?
I took the liberty of adding /code/ tags to your post - Phage
-
Figured it out. First off, your getElementById's had an L in it instead of an I "getElementByld".When I figured that out and got the alert to appear there wasn't any text in your variables showing up so I put .value on the end of the variables that you were making which got it to show up. Hopefully this helped and this was explained well enough as too why it wasn't working. Here's the code below.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Javascript Test</title>
<script src="Test.js"></script>
</head>
<body>
<input type="text" name="txtFirstName" id="txtFirstName" placeholder="First Name" />
<br />
<br />
<input type="text" name="txtLastName" id="txtLastName" placeholder="Last Name" />
<br />
<br />
<button onclick="CombineName();">Click Me</button>
</body>
</html>
JavaScript
function CombineName()
{
var FirstName = document.getElementById("txtFirstName").value;
var LastName = document.getElementById("txtLastName").value;
CombineName5 = FirstName + " " + LastName;
alert("Hello, " + CombineName5);
}