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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:42:09+00:00 2026-06-18T01:42:09+00:00

Well, I need to insert a HTML string with php code inside in a

  • 0

Well, I need to insert a HTML string with php code inside in a form.

I have one form to create new users. Inside of it, I need to insert a role for this user, so I have some roles in my database to apply to him.

I have a html select field to do that, and a button to add a new rol. When I click in the button, I want to add a new select field to my form. But inside this code I have PHP code to show all roles. I try this way using jQuery:

$(document).ready(function () {
    $('#add-role').click(function (event) {
        var newRoleField = "<label for=\"usuario_perm_id\">ROLE <span class=\"required-field\"> * </span>:</label>" +
            "<select id=\"usuario_perm_id\" name=\"usuario_perm_id\" tabindex=\"7\">" +
            "<option <?php echo ($this->usuario[\"rol_id\"] == \"none\" ? 'selected=\"selected\"' : null); ?> value=\"none\">-- Seleccione un rol --</option>" +
            "<?php foreach ($this->roles as $rol): ?>" +
            "<option value=\"<?php echo $rol[\"rol_id\"]; ?>\" <?php echo ($this->usuario[\"rol_id\"] == $rol[\"rol_id\"] ? 'selected=\"selected\"' : null); ?>><?php echo $rol[\"nombre\"]; ?></option>" +
            "<?php endforeach; ?>" +
            "</select><br />";

        $('#new-roles').append(newRoleField);

        event.stopPropagation();
        event.preventDefault;
    });
});

And I get a new select field but inside it, the text:

usuario["rol_id"] == "none" ? 'selected="selected"' : null); ?> value="none">-- Select role --

  • 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-18T01:42:10+00:00Added an answer on June 18, 2026 at 1:42 am

    You can’t. JavaScript (and thus also jQuery) runs client side and PHP runs server side. The browser has no idea how to handle any PHP you might insert.

    A way to handle this, is to have jQuery query the server for the roles and have your server create a (PHP generated) list of roles. Check out AJAX.

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

Sidebar

Related Questions

I'm using PHP and I need to insert a new record in a MySQL
I need to insert an Omega (Ω) onto my html page. I am using
I need to submit an html form via .ajax with jQuery. When I submit
I have an odd issue. I have one PHP script that is used for
I am trying to create a simplified code to insert images dynamically into a
Well, this is my question. I need to insert data in the three tabblas
I need insert some elements in a field array on a document. Well... I
Basically I have an html form for inserting a product. The field names, as
my html form is bellow and process this page with add_post_process.php. In this page
I insert a value / new row and I need the ID, but I

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.