Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging text for an input field using php, mysql, and javascript
    text
    copied!<p>Ok, i have some data that is being populated via a php query to a database. I am getting comments that a user enters. I am displaying the returned data in a variable as shown below. If a comment does not exist then it would display an "add comment" link. The comment is just displayed as text at first. If a comment exists then it would display the comment along with an "edit" comment" link.</p> <p>This is the functionality i am looking to have: 1) when you click on "add comment" an input field would be displayed to the left of the "add comment" link and that link would then turn in to two links that read "save" and "cancel". I know how to do the save link but i would like to know how to make the "cancel" link revert the area back to just having the "add comment" link. 2) when you click on "edit comment" then i would like the same functionality with an input field and the "save" and "cancel" links; however, i would like the input field to be pre-populated with the comments text that is being pulled via the comments variable. I'm thinking maybe this can be done with some css display toggling none and block/inline. Not sure exactly though. Any help is greatly appreciated!</p> <p>PHP Code:</p> <pre><code>if(!$comments){ echo "&lt;span style='font-size:12px;'&gt;[&lt;a href='#'&gt;Add a Comment&lt;/a&gt;]&lt;/span&gt;"; }else{ echo "&lt;span style='font-size:12px;'&gt;NOTES: " . $comments . " [&lt;a href='#'&gt;Edit Comment&lt;/a&gt;]&lt;/span&gt;"; } </code></pre> <p>One final question: how should i handle if the comments have special characters or quotes? Actually i guess i'll need to worry about those before teh variable is created, correct? How do i do that? Thanks so much!</p> <p>UPDATE: I appreciate the help on handling special characters, but i really need the first two questions answered more. Thanks for any more help anyone can provide me!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload