Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    Wisconsin
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I am having a problem passing a variable from HTML to JavaScript

    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">
    <head>
    <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>
    <![endif]-->
    <SCRIPT LANGUAGE="JavaScript" type="text/javascript" src="script1.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript">

    function GetPage(){

    document.write("OK")
    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)
    if(word[2]){
    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)
    document.write(page)

    <!-- window.location.pathname = page
    }
    </script>
    </head>
    <body>
    <center>
    <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>
    </form>
    </center>
    <BR><BR><BR>
    This is the end
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Location
    madison, *****sconsin
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post
    <form action="javascript:doSomethingWith(document.getElementById('golfname').value);" >
    <input id="golfname" name="whatever" placeholder="golfer">
    <input type="submit" >
    <script>
    function doSomethingWith(redalert){
    alert(redalert);
    }
    </script>

  • Users who have thanked progressionner for this post:

    ronrumpf (09-13-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •