Jump to content

Insert element using PHP


jessecasimsiman

Recommended Posts

I just learned that jquery can insert every element in the set of matched elements after the target, using .insertAfter().How can I do it in PHP? My target is, when user click the insert button of a certain form, it calls php file that adds html element to the existing document.

Link to comment
Share on other sites

PHP cannot directly affect an existing document. For PHP to insert elements, the page must be reloaded.You can, however, use JavaScript to send an AJAX request to PHP and have PHP return an HTML string which you can then use in JavaScript to insert your element.

Link to comment
Share on other sites

PHP cannot directly affect an existing document. For PHP to insert elements, the page must be reloaded.You can, however, use JavaScript to send an AJAX request to PHP and have PHP return an HTML string which you can then use in JavaScript to insert your element.
Thank you. It looks like I need to learn AJAX as well :)
Link to comment
Share on other sites

Thank you. It looks like I need to learn AJAX as well
Just so you're clear, AJAX is not another language. It is simply a JavaScript technique used to communicate with a server-side language.You can start here if you want to learn how to make an AJAX request.
Link to comment
Share on other sites

Apologies if I'm hijacking, but my issue is so, so similar.I want to have javascript act in a certain way according to variables set up in PHP. Would having a look at AJAX be wise for me also?Thanks,Mark.

Link to comment
Share on other sites

I want to have javascript act in a certain way according to variables set up in PHP. Would having a look at AJAX be wise for me also?
Depends. Do those variables change based on user interaction? Do they require PHP to change them? If so, then yes, AJAX would be the way to go. If those values never need to change, you can just write those values either directly in the JS or in a hidden HTML input and read them using javascript.
Link to comment
Share on other sites

Depends. Do those variables change based on user interaction? Do they require PHP to change them? If so, then yes, AJAX would be the way to go. If those values never need to change, you can just write those values either directly in the JS or in a hidden HTML input and read them using javascript.
I had planned on setting up display: none elements and then using javascript to alter the display. Yet there will also be instances where a PHP instruction will alter an element that is to be displayed.e.g. I have a Sign-In element that will, upon mousedown, display a Sign-In box. But, once signed-in, I want the element to say "Log Out" and behave differently upon a click of the mouse.What I'm wondering is whether I can use Javascript to read a variable that has been set in PHP (such as signInStatus) and then use Javascript to process the display requirements?Thanks,Mark.(If this "interruption" to jessecasimsiman's thread continues I'll start a new thread. :) )
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...