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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:55:05+00:00 2026-05-17T22:55:05+00:00

I just wrote some code, looked it over, and wanted to cry. Lines that

  • 0

I just wrote some code, looked it over, and wanted to cry. Lines that end in .’\’);”>’; cannot be a good thing.

I’m writing an ajax function to return a new row to add to a table. The row uses javascript to be user editable.

$ident=mysql_insert_id().'_c_label';

    $html='<tr>';
        $html.='<td class="label" id="'.$ident.'" onclick="editTextStart(\''.$ident.'\');">';
            $html.='<div>';
                $html.='<span id="'.$ident.'_field">'.self::default_label.'</span>';
                $html.='<input id="'.$ident.'_input" type=text onblur="editTextEnd(\''.$ident.'\');" onclick="editTextEnd(\''.$ident.'\');"/>';
            $html.='</div>';
        $html.='</td>';
        $html='<td>';
        $html.='</td>';
        $html='<td>';
        $html.='</td>';
        $html='<td>';
        $html.='</td>';
    $html.='</tr>';

    return $html;

So how should I be going about this to get html and javascript variables out of my php?

  • 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-17T22:55:06+00:00Added an answer on May 17, 2026 at 10:55 pm

    Use an external JavaScript file, which you include with a script tag just before your closing </body> tag (or in the head, there are trade-offs — off-topic discussion of them below). You can hook up event handlers at that point by using DOM selectors and/or IDs and attachEvent (IE) or addEventListener (standard).

    For instance, say your structure looks like this:

    <table id='niftyStuff'>
        <tbody>
            <tr>
                <td>Cool</td>
                <td>Stuff</td>
            </tr>
            <tr>
                <td>Cool</td>
                <td>Stuff</td>
            </tr>
        </tbody>
    </table>
    

    Then with straight JavaScript+DOM methods, you can hook up a click handler to the cells like this:

    var table, cells, index;
    table  = document.getElementById('niftyStuff');
    cells = table.getElementsByTagName('td');
    for (index = 0; index < cells.length; ++index) {
        hookEvent(cells.item(index), 'click', clickHandler);
    }
    
    function clickHandler() {
        // Handle the click; `this` will refer to the cell
    }
    
    // Convenience function defined somewhere to smooth out IE/Standards
    function hookEvent(element, name, handler) {
        if (element.attachEvent) {
            element.attachEvent("on" + name, handler);
        }
        else if (element.addEventListener) {
            element.addEventListener(name, handler, false);
        }
        else {
            throw "Unsupported browser";
        }
    }
    

    (Or you can define hookEvent in a way that only looks for which version to use once, but it would be over-complex for the example above.)

    Off-topic, but if that hookEvent looks awkward, a using a library like jQuery, Prototype, YUI, Closure, or any of several others can really help smooth these browser differences out.

    For instance, with jQuery:

    $('#niftyStuff td').click(clickHandler);
    function clickHandler() {
        // Handle the click; `this` will refer to the cell
    }
    

    (Edit Sounds from your comment below like you’re using jQuery, so here’s a live example for the above.)

    With Prototype:

    $$('#niftyStuff td').invoke('observe', 'click', clickHandler);
    function clickHandler() {
        // Handle the click; `this` will refer to the cell
    }
    

    Off-topic: I said above to put your script tag at the end of the body. That’s just one choice. If you do, the DOM will reliably be ready to be searched, etc., you don’t have to wait for window.onload which happens much, much later or rely on “ready” events. But if your script file isn’t coming from the browser cache, there’s a delay while your page may be showing (and your user clicking) before you hook things up. On the up side, your page displays more quickly (because the script file didn’t hold things up by being in the head); on the downside, you probably don’t want them frustrated by clicking before you’re ready (although the gap is quite small). So where you put it is a balance between those things. If you’re worried about people jumping on clicks, put the script in head but then have a small script tag at the end of body that calls a function defined in the file that hooks things up. Or use a ready event (most libraries provide them). Or there are sophisticated strategies to use a small inline script to capture and defer clicks.

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

Sidebar

Related Questions

I just wrote my first web service so lets make the assumption that my
I just wrote an if statement in the lines of if (value == value1
I have a macro that I wrote to just help me with my unit
I just wanted to pause in an F# console application, so I wrote: Console.ReadKey()
I've got an application that just shipped. Since I wrote it, I've learned about
I'm trying to write a web application using SpringMVC. Normally I'd just map some
I just wrote a new web part and now I am getting this error
I just wrote the following C++ function to programmatically determine how much RAM a
I wrote a simple web service in C# using SharpDevelop (which I just got
I just lost 50% of my answer on a test because I wrote the

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.