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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:18:33+00:00 2026-06-01T18:18:33+00:00

I have a php that echos html. Inside one of these echos I have

  • 0

I have a php that echos html. Inside one of these echos I have a button that calls a javascript function. Inside of this call I pass a php variable. However when I see what the value of one of the elements is inside of the javascript I get undefined.

Any ideas?

Javascript

function addrow(innerid, teams){


    alert(teams[1]);}

Here is how I pass it, this is all inside of an echo

<input type = "button" id = '.$buttonid.'  value = "Agregar" onclick = "addrow(\'' . $leaguesarray[$numofleagues] . '\','.$teamsarray.')

So I call addrow(with a league value, and I also pass the array teamsarray from php

I’ve decided to try something else but I’m not getting it to work correctly.

Any suggestions?

echo '<script language="javascript">';


for ($size = 0; $size < sizeof($teamsarray);$size++){

    echo "var teamsarray[".$size."] = ".$teamsarray[$size].";\n";


    }

echo 'function addrow(innerid, size){


for (var i = 0;i< size; i++ ){

html = html + "<option value = " + teamsarray[i] + ">"+teamsarray[i]+"</option>";


    }

html = html +"</select>";
}</script>';

basically what I’m trying to do is echo the javascript through php. I’m trying to make a dropdown with values that I get from php. Which will be added dynamically with the addrow function.

  • 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-01T18:18:34+00:00Added an answer on June 1, 2026 at 6:18 pm

    It sounds like you might be looking for json_encode, so you might do something like this:

    if (empty($teamsarray)) $teamsarray = array();
    echo '<input type = "button" id = '.$buttonid.'  value = "Agregar" onclick = "addrow(\'' . $leaguesarray[$numofleagues] . '\','.json_encode($teamsarray).'); return false;" />';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have a PHP script (index.php) that includes an index.html file in a sub-directory
I have a PHP script that publishes customised JavaScript based on the parameter, with
I have some images inside links that I want to essentially look like this:
I have a PHP function that I'm using to output a standard block of
I have a run.php that has a button on it called Run. Clicking it
I'm trying to echo a js function in HTML string inside PHP echo. And
I have this PHP code I am trying to integrate with the html layout
I have a javascript character counter that I use inside of a text area.

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.