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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:25:26+00:00 2026-06-12T01:25:26+00:00

Hello, I have problem with my JS function. Please help me, I need this

  • 0

Hello, I have problem with my JS function.
Please help me, I need this code until today and I can’t understand what is the wrong 🙁

  foreach($group as $i => $name){
   print'<li onclick="groups(\'group'.$i.'\');" >'.$name.'</li>';
}

Then I have this code:

$moretags = "<script>";
$moretags .= 'function groups(grid){';
  foreach($group as $i => $name){
  $moretags .= '
  if(grid == \'group'.$i.'\'){
  document.getElementById(\'show\').innerHTML = \'group'.$i.'\';
  }
  ';

}


$moretags .= '</script>';
  • 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-12T01:25:27+00:00Added an answer on June 12, 2026 at 1:25 am

    I completely agree with Felix Kling that you shouldn’t generate JavaScript code with PHP code unless you really know what you’re doing, which you apparently do not.

    It is impossible to solve your problem because of the lack of details in your question but I’ll try to at least help you make your code less error prone.

    All you should generate in your PHP should be the HTML tags (at most!) without any onclick attributes, only classes and maybe some ids. Then just add the relevant event handlers in JavaScript (and use some framework like jQuery – read this to see why) or you can even add the HTML elements in JavaScript if they can’t be used without JavaScript anyway.

    Code generation is a hard thing. Generating JavaScript in PHP won’t get you very far.

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

Sidebar

Related Questions

Hello i have problem with putting logs using multithreading, my function loks like this
I have this code - jQuery('.wymeditor').wymeditor( { html: '<p>Hello, World!<\/p>', postInit: function(wym) { var
hello I am having problem related to https:// . I have used FB.getLoginStatus(function(response) function
Hello i have the following problem, I record a video using red5 like this:
I have this problem when trying to run hello world program using android SDK.
Hello guys I have this code in main.php config file: 'components' => array( '[.........]',
Hello I have this callback function when an image is uploaded to the server
Hello please help me out regarding returning the variable from the function I am
Hello I have applied jquery show/hide function in my website but the problem is
Hello I have problem to put together animations of two separate objects to second

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.