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 8478839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:51:30+00:00 2026-06-10T18:51:30+00:00

I am trying to pass a value from javascript to php using POST method

  • 0

I am trying to pass a value from javascript to php using POST method but it is not working .Here is the code:

<head>
<script type="text/javascript">
function Email()
{

    var e=prompt("Your Email","");
    if(e==null||e=="")
    {
    alert("You need to enter an email..Try again");
    Email();
    }

    return e;
}
function Code()
{

    var f=prompt("Activation code","");
    if(f==null||f=="")
    {
    alert("You need to enter the code..Try again");
    Code();
    }

    return f;
}
</script>
</head>
<body>
<form method="post">
<input type="hidden" id="Email" name="Email" />
<input type="hidden" id="Code" name="Code" />
</form> 
<script>
var email=Email();
var code=Code();
document.getElementByID("Email").value=email;
document.getElementByID("Code").value=code;
</script>

<?php
$email=$_POST["Email"];
$code=$_POST["Code"];

echo $email.$code;
?>
</body>

I get these errors :

  • Notice: Undefined index: Email
  • Notice: Undefined index: Code

Anybody please help me out…

  • 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-06-10T18:51:32+00:00Added an answer on June 10, 2026 at 6:51 pm

    Okey if you want to print those values you need to create a form form them, a proper one. If you just want to submit form no need for JS there because if you just want to submit some values there is no need for form, you want to use jQuery Post for that.

    <form method="post" action="">
        <label for="email">Email</label>
        <input type="text" name="email" />
    
        <label for="code">Code</label>
        <input type="text" name="code" />
    
        <input type="submit" value="Submit" />
    </form>​
    

    Fiddle: here

    Edit

    Then this is what you want. (Note that this code is using jQuery library)

    $(function(){
        // Create both variables
        var code, email;
    
        // Ask for code and check if it's not null or empty
        do{
            code = prompt('Activation code', null);
        }
        while(code == null || code == '');
    
    
        // Ask for email and check if it's not null or empty
        do{
            email = prompt('Your email', null);
        }
        while(email == null || email == '');
    
        // Make POST request via AJAX to your script
        $.post('yourscript.php', { code: code, email: email }, function(data) {
            // If success alert response (in your case should be "email.data" values)
            alert(data);
        });   
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass a value from php to javascript. I understand one
Am trying to pass an array of values from PHP function to Javascript. Not
I have been trying to pass a string value from one method into another.
I'm trying to pass value by using EL expression in get request parameter, but
I am trying to pass a Hexadecimal color value from objectiveC to Javascript. I
I'm trying to pass a parameter from php into my javascript function inside html.
I'm currently trying to pass Silverlight a string value from the parent JavaScript. The
I am trying to pass a variable from evercookie to PHP using New Image()
I'm trying to pass multiple values from PHP into my javascript function. The function
I am trying to pass javascript code from 1 page of my website to

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.