?
Solved

how to get html textbox values into javascript variables

Posted on 2012-08-22
2
Medium Priority
?
765 Views
Last Modified: 2012-08-22
I am not sure what I am doing wrong here, but I have a super simple HTML page that has txt boxes for first name and last name. I would like to get the text in those text boxes and put that into a javascript variable. My end goal would be to write this data to a SQL server database table. However for now, I would like to just figure out how to "alert" the variables after they have been populated. My code is below:

<html>
<head>
    <!--
    Put comments here
    -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Data Entry</title>

    <script type="text/javascript">
        function getTextValues()
{
    
    var fname = document.getElementById('txtFname').value;
    var lname = document.getElementById('txtLname').value;
    alert(fname);
    
    
    }
    </script>
    

</head>

<body>
    <form>
    First name:<input value="" type="text" id="txtFname" name="firstname" />
    Last name:<input value="" type="text" id="txtLname" name="lastname" />
    </form>
   
    <form>
        <button onclick="getTextValues()">CLICK ME</button>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:sqlagent007
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 38322380
Working fine here on IE9 and Firefox and Chrome
Is that really all the code on the page.
0
 
LVL 1

Author Closing Comment

by:sqlagent007
ID: 38322458
Apparently I had to allow the "blocked content".
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question