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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:20+00:00 2026-05-22T23:35:20+00:00

On my page I have many forms, in witch field ids are generated based

  • 0

On my page I have many forms, in witch field ids are generated based on DB id. like this:

            <input type="hidden" name="id" value="<?php echo (isset($content))?$content->getId():''?>" />
            <input type="hidden" id="x<?php echo $content->getId()?>"/>
            <input type="hidden" id="y<?php echo $content->getId()?>"/>
            <input type="hidden" id="x2<?php echo $content->getId()?>"/>
            <input type="hidden" id="y2<?php echo $content->getId()?>"/>

That gives me unique ids for all forms.
Now I have Javascript function in jquery framework that sets vale of specified field that doesnt work:

            $(function(){
                $('#jcrop_target_id<?php echo $content->getId()?>').Jcrop({
                    onSelect: updateCoords
                });
            });

            function updateCoords(c)
            {
                $('#x<?php echo $content->getId()?>').val(c.x);
                $('#y<?php echo $content->getId()?>').val(c.y);
                $('#x2<?php echo $content->getId()?>').val(c.x2);
                $('#y2<?php echo $content->getId()?>').val(c.y2);
            };

Values c.* are OK, but obviously #x<?php echo $content->getId()?> doesn’t work.
What is the proper way to do it?
Regards.

  • 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-05-22T23:35:21+00:00Added an answer on May 22, 2026 at 11:35 pm

    Attempting to mix php and javascript can be pretty difficult. The reason for this is that they are not processed at the same time, or in the same way. PHP gets processed first on the server and the results of that process are sent to the browser. Then any javascript is processed.

    Additionally, I don’t think that php tags inside of javascript will actually be processed, but I’m not 100% certain about this.

    One thing that you can do (but often looks pretty ugly) is to use php to actually create your javascript. For example:

    echo '<script type="text/javascript">';
    echo 'function updateCoords(c) {';
    echo '    $(\'#x' . $content->getId() . '\').val(c.x);';
    ...
    echo '}';
    echo '</script>';
    

    Like I said, it looks pretty ugly so I don’t really recommend it, but it should actually work like you want.

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

Sidebar

Related Questions

I have a page with many forms in panels and usercontrols, and a requiredfield
I have a page with many forms on it. could be 1..200. None of
If I have a single page with many forms of existing records: index.html.haml -
I have a page with many forms on it. Each form has a unique
i have many forms on one page. i'm using jquery and ajax to update
I have many links in my page. For example <a href=/promotions/download/schools/australia.aspx>Australia</a> Now I want
i have many events such as $('.hidefile').click(function (event) { On page load and on
how can i do. i have many html elements on page. after clicking on
I have a page upon which a user can choose up to many different
Many applications have grids that display data from a database table one page at

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.