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

  • Home
  • SEARCH
  • 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 8522821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:14:06+00:00 2026-06-11T07:14:06+00:00

I’ve got a <select element on a php/xhtml page. Instead of using a submit

  • 0

I’ve got a <select element on a php/xhtml page. Instead of using a submit button, I’m trying to implement the Javascript onchange() and submit()method. I need to pass multiple variables to make up for the lost hidden field. The onchange and submit methods are firing, but I can’t get it to trigger the PHP isset which is on the same page.

<?php
if(isset($_POST['companykey'])){
$nowIveGot1 = $_POST['COMPANYKEY'];
$nowIveGot2 = $_POST['USERNAME'];
?>

<script language="javascript">
function copy(selectedValuePassed, selectedNamePassed, userIDPassed, formNamePassed) { 
var formNameReceived = formNamePassed;
var userIDReceived = userIDPassed;
var selectedValueReceived = selectedValuePassed;
var selectedNameReceived = selectedNamePassed;

var form = document.createElement("form");     
form.setAttribute("method", "post"); 
form.setAttribute("action", ""); 
form.setAttribute("name", formNameReceived);
form.setAttribute("id", formNameReceived);

var valueSelected = document.createElement("input"); 
valueSelected.setAttribute("type", "hidden"); 
valueSelected.setAttribute("name", selectedNameReceived); 
valueSelected.setAttribute("id", selectedNameReceived);
valueSelected.setAttribute("value", selectedValueReceived);
form.appendChild(valueSelected); 

var passusername = document.createElement("input");
passusername.setAttribute("type", "hidden");
passusername.setAttribute("name", "USERNAME");
passusername.setAttribute("id", "USERNAME");
passusername.setAttribute("value", userIDReceived);
form.appendChild(passusername);

document.body.appendChild(form); 
form.submit(); 
} 
</script>

<select onchange="copy(this, 'COMPANYKEY','jarrett', 'companykey');">
  <option value="Text1">Text 1</option>
  <option value="Text2">Text 2</option>
</select>

SOLVED: Create a parent element for valueSelected and passusername. Name it the isset check name.

  • 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-11T07:14:08+00:00Added an answer on June 11, 2026 at 7:14 am

    If I am understanding your problem…

    <?php
    if(isset($_POST['companykey'])){
        $nowIveGot1 = $_POST['COMPANYKEY'];
        $nowIveGot2 = $_POST['USERNAME'];
    }
    

    The $_POST['companykey'] will always be null and the if conditonal will never execute.

    This is because key value pairs are not passed into the $_POST array when they are attached to the <form> element, only the embedded <input>‘s.

    In your javascript, you pass 'companykey' as the last argument to copy. From there it is assigned to formNameReceived. You then assign it to the name attribute of the form with:

    form.setAttribute("name", formNameReceived);
    form.setAttribute("id", formNameReceived);
    

    'companykey' will never appear in the $_POST array like this, it’s not attached to an input, but rather the form itself.

    As a vanilla HTML analogue, imagine this:

    <? print_r($_POST);?>
    <html>
    <body>
    <form method='post' name='cat' value='dog'>
        <input type='hidden' name='foo' value='bar'/>
        <input type='submit'/>
    </form>
    </body>
    </html>
    

    No matter how many times you submit this form, it will never contain the cat -> dog pair. If you want 'companykey' to appear in the array, you’ll have to assign it to another hidden input.

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

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I want to count how many characters a certain string has in PHP, but

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.