textbox value to an alert on click

Posted on 2010-01-06
Last Modified: 2012-05-08

I want  a value from a html text box to appear in an alert when clicking a button. I think I need to do this using javascript. does any one have an example I can use please?

Question by:ac_davis2002
    LVL 20

    Assisted Solution

    Check the onclick section of this page -
    LVL 21

    Accepted Solution

    yes, you need javascript....

    onclick of a button do this:

    function theClick(){
    var ele = document.getElementById("txtBoxID");
    alert (ele.value);

    LVL 21

    Assisted Solution

    <input type="button" onclick="theClick">
    <input type="text" id="txtBoxID" name ="txtBoxID">...

    to conclude my example...

    <script type="text/javascript">
           function theClick(){
    var ele = document.getElementById("txtBoxID");
    alert (ele.value);

    LVL 4

    Expert Comment

    Silemone, don't you have to place () with the function in the onclick attribute? Like this?:

    <input type="button" onclick="theClick()" />

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now