in Education by
been working on some database data calling into a .php file. The php file contains an "Add" button, a "textarea" and an "submit" button. I did added some J Query script to it to make the "textarea and submit" button to hide until "add" button is clicked, and both "textarea and submit" to hide when "submit" button is clicked making "add" button reappear. Ever thing is working fine but only glitch is, the script is only working for first row in the table, leaving the rest of rows uneffected. I think i should use a loop or something.. spent couple of hours but couldn't able to figure it out by myself. my script goes as follows: <!DOCTYPE html> <?php $servername = "localhost"; $username = "root"; $password = "*****"; $dbname = "the_database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); $sql = "SELECT * FROM input"; $result = $conn->query($sql); ?> //<![CDATA[ $(window).load(function(){ $().ready = function() { $('#text').hide(); $('#textsubmit').hide(); $("#addanswer").click(function() { $('#addanswer').hide(); $('#text').fadeIn('slow').focus(); $('#textsubmit').fadeIn('slow'); }); $('#text').blur(function(){ $('#text').hide(); $('#textsubmit').hide(); $('#addanswer').fadeIn('slow'); }); }(); });//]]> <?php if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { ?> <?php } } else { echo "0 results"; } $conn->close(); ?> JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Since you cannot have multiple occurrences of the same ID, you could do something like this. <?php foreach( $your_data as $index => $data ){ echo ''; echo ''; // I dont think openning form from row to row would be nice! echo ' '; echo ''; echo ''; } ... Other code stuff. Now the each row is having a different ID because we have used $index variable. And also we pass the $index to the javascript function as well. So the javascript can do what ever based on the $index value. You can have your javascript function, something like this. function addanswer(index){ $('#addanswer_' + index).hide(); $('#text_' + index).fadeIn('slow').focus(); $('#textsubmit_' + index).fadeIn('slow'); } Note: I havent checked this code by running it. I think you will get some understanding with this. Thanks

Related questions

0 votes
    This is nagendra, I am new to the wordpress, Can anyone explain how to add Jquery ui slider to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    I am implementing a design that uses custom styled submit-buttons. They are quite simply light grey buttons ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have a php file and it contains a textfiled and submit button and a div and below is code Page1 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a php file and it contains a textfiled and submit button and a div and below is code Page1 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a database (SQL Server) with clients and a MVC plataform, and i want a row to be "hidden ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a database (SQL Server) with clients and a MVC plataform, and i want a row to be "hidden ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a rails application which is api only i am using gem rails-api. Now I am trying to create ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    Take from a pack of cards all the Aces, Kings, Queens and Jacks. Arrange them in a 4 × 4 square so that every ... and one card of each suit (Heart, Spade, Diamond, Club)....
asked Feb 11, 2021 in Education by JackTerrance
0 votes
    I have a mat-table with a component app-order-statuses on every row. the component calls the statuses ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I'm working on Windows c#. Firstly, the things those can not be change as my need are following: The Size of TableLayoutPanel is ... .Drawing.Size(555, 200); for (int i = 1; i...
asked May 22, 2022 in Education by JackTerrance
0 votes
    Want to improve this post? Provide detailed answers to this question, including citations and an explanation of ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I'm trying to make the text move continuously by pressing a button but right now it only moves an ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I want to make a new span class called "button". When the "button" is clicked, it should run ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I have an attribute and I'd like to make the coercion fire on every input value. Prior to 0.72 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
...