Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1001773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:43:42+00:00 2026-05-16T07:43:42+00:00

How do you use a value submitted by a form in javascript? Facts: It

  • 0

How do you use a value “submitted” by a form in javascript?

Facts:
It is a PHP document
I’m using JavaScript because I need some timing factors I don’t think I can get from serverside-scripts 🙂

To simplify; what I want is, that when this form is submitted or a button is clicked:

<form method="POST" action="test.php">
<input type="text" name="foo" size="30">
<input type="submit" value="Click me"> //it doesn't have to be submitted
<input type="button" action="some_action" value="Click me"> //an alternative solution
</form>

the value of the text-input named “foo” is displayed elsewhere.

NOTE The form doesn’t have to be submitted, what I realy want is, that when you press a button the value can be used elsewhere

Should I use GET instead? Can I just use the $_POST array? Should I use AJAX (which I am completely useless at)? I don’t know what to do in this situation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:43:42+00:00Added an answer on May 16, 2026 at 7:43 am

    Since you mentioned that it does not depend fully upon whether the form is submitted or not, so it’s more easier to catch the value w/o POSTing / GETing the form. After you have written your interface logic in the body section, you need to write the following code in the footer page at the end:-

    anypage.php:-

    <form method="POST" action="test.php">
      <input type="text" name="foo" id="foo" size="30" />
      <input type="submit" onclick="return writeFoo('foo_placeholder', 'foo');" value="Click me" /> //it doesn't have to be submitted
      <input type="button" onclick="return writeFoo('foo_placeholder', 'foo');" action="some_action" value="Click me" /> //an alternative solution
    </form>
    

    The above code is your code only with some minor modifications, including calling a JS function “writeFoo()” on the “click” event of either a button / submit. This function takes 2 arguments:-

    • arg – It mentions the destination placeholder ID of the HTML element, in which the value is to be printed.
    • source – It mentions the source ID of the HTML element, from which the value is to be grabbed / taken.

    rightpart.php:-

    <div>
        <span id="foo_placeholder"></span>
    </div>
    

    The above HTML code can be used for any panel, but must be included when the “anypage.php” page is to be shown to the user. This is because the placeholder element must be present when the “foo” element is being called. Be careful to use the same ID both in the “writeFoo()” function calling time & in this page.

    footer.php:-

    <script type="text/javascript"><!--
    function writeFoo(arg, source) {
        if(document.getElementById(arg) != null) {
            document.getElementById(arg).innerHTML = document.getElementById(source).value;
        }
    }
    // --></script>
    

    And this page should contain the above JS code containing the definition of the “writeFoo()” function.

    EDIT, as for @Latze:-
    See you can include that “rightpart.php” page either in the same block of “anypage.php” page or in any block of any other page (like “header.php” / “footer.php” page). But the main logic is that both the source ID (from which the value is taken) & the target / placeholder ID (where the value is to be shown) must be present when you are viewing that particular page (in this case, it means when you are viewing the “anypage.php” page).

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a variable value in exec where i don't need to
I have a select field within a form: <form id=myform> <select id=value onchange=javascript: document.myform.submit()>
I've got form which when submitted (using AJAX) returns a bunch of client details.
I have a working example of a form here . I need to use
I'm working on one application ( using PHP, javascript ). Below is the short
I am using fancybox to open submitted form like this: <form name=form id=myForm action={$smarty.server.PHP_SELF}?action=abc
I need to create a simple calculator that computes 1% of the value submitted
I'm trying to use a value from onsubmit() in php. More specific: An HTML
I'm currently using php to populate a form with selections from a database. The
I use datetime picker for ASP.NET MVC with razor, when submitted form got validation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.