View Full Version : I am having a problem passing a variable from HTML to JavaScript

09-12-2011, 03:19 AM
I have two versions of this document. The first version uses only JavaScript and the standard PROMPT(). It works very well, but I would like to insert the name prompt into the page using the input command. For some reason the variable loaded in the HTML statement doesn't get passed to the JavaScript. Any ideas would be appreciated! This is only a small test page. Sorry I don't know about the [code] tag...

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
<meta name="created" content="Sat, 10 Sep 2011 19:40:31 GMT">
<meta name="description" content="">
<meta name="keywords" content="">
<title>Enter golfers name</title>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript" src="script1.js"></SCRIPT>

function GetPage(){

var lab = "";
var result = fullname.toUpperCase();
var word=result.split(" ");
fname = word[0]
lname = word[1]
alpha = lname.slice(0,1);
lab = fname.concat("_")
lab = lab.concat(lname)
ext = word[2]
lab = lab.concat("_")
lab = lab.concat(ext)
var intro = "./Stats_";
page = intro.concat(alpha);
page = page.concat("_golfers.html#");
page = page.concat(lab)

<!-- window.location.pathname = page
<form action="form_action.asp" method="get">
You can enter the golfersname or select him from the above list.<br><br>
<input type="text" name="fullname" />
<button type="submit" onclick="GetPage()">GO</button>
This is the end

09-12-2011, 06:24 AM
<form action="javascript:doSomethingWith(document.getElementById('golfname').value);" >
<input id="golfname" name="whatever" placeholder="golfer">
<input type="submit" >
function doSomethingWith(redalert){