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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:21:48+00:00 2026-06-14T17:21:48+00:00

I have a code below where it displays a text input in one column,

  • 0

I have a code below where it displays a text input in one column, the total marks column in the second column and the marks remaining in the last column. The table looks like this below:

Marks Per Answer       Total Marks    Marks Remaining
(blank text input)      4              4
(blank text input)      6              6

But the problem I have is that the text inputs are empty, they should display a value of the “Total Marks” column (so 4 for the first text input and 6 for the second text input).

Also as both text inputs contains the total marks, under the “Marks Remaining” column, both rows should display 0. (for first row 4 from text input minus 4 under Total marks makes 0 for Marks Remaining for first row. For second row 6 from text input minus 6 under Total marks makes 0 for Marks Remaining for second row)

So the table should really look like this below:

Marks Per Answer              Total Marks    Marks Remaining
(text input value=4)            4              0
(blank text input value=6)      6              0

My question is that how can both steps above be solved by changing the jquery below:

$(function() {   
    //alert("here");         
    var questions = $('#markstbl td[class*="_ans"]').length;

    //disable single entry
    for (var i=0;i<=questions;i++){   
    if($("[class*=q"+i+"_mark]").length ==1){
    var t_marks = $("[class*=q"+i+"_ans]").html();
    //alert(t_marks);
    alert(t_marks);
    $("[class*=q"+i+"_mark]").val(t_marks).attr("disabled","disabled");
    //$("[class*=q"+i+"_mark]").attr("disabled","disabled");
    }                    
    }
    }

Below is the dynamic HTML table:

<table border='1' id='markstbl'>
<thead>
<tr>
<th class='answermarksth'>Marks per Answer</th>
<th class='totalmarksth'>Total Marks</th>
<th class='noofmarksth'>Marks Remaining</th>
</tr>
</thead>
<tbody>

<tr class="questiontd">
<td class="answertd" name="answers[]"><?php echo$searchAnswer[$key]?></td>
<td class="answermarkstd">
<input class="individualMarks q<?php echo$questionId?>_mark_0"  q_group="1" name="answerMarks[]" id="individualtext" type="text" />
</td>
<?php
    if($questionId != $prev_ques){
    ?>
<td class="totalmarkstd" rowspan="<?php echo$row_span[$questionId]?>"><?php echo$totalMarks[$key]?></td>
<td class="noofmarkstd q<?php echo$questionId?>_ans_text"  q_group="1" rowspan="<?php echo$row_span[$questionId]?>"><?php echo"<strong>".$searchMarks[$key]."</strong>"?></td>
<?php
    }
    ?>
</tr>
<?php
$prev_ques = $questionId;
}
?>
</tbody>
</table>

At the moment in the jquery function I am trying to use the t_marks variable to display the value in the text input but nothing is displayed within each SINGLE text input within a table row

  • 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-06-14T17:21:49+00:00Added an answer on June 14, 2026 at 5:21 pm

    I think I got it figured out for you. See http://jsfiddle.net/jhfrench/NsWRv/

    I use jQuery to loop through the input elements classed as ‘.individualMarks’ with ('input.individualMarks').each(...), then use parent() to find the input’s parent td. From there, I get the values of that td’s siblings, then perform the simple math and assign the resulting value to the “marks remaining” column.

    I take it one step further by assigning on onChange event that refires the updating function every time the input fields are manipulated.

    If there will be many fields on this page, you might invest time in converting this into a plugin so you can execute it against jQuery objects and only update rows that pertain to the updated input field (right now it recalcs for all the inputs/table rows for a change to any input).

    I’m not familiar with PHP, but I think your original code would result in duplicate IDs. Try to avoid that!

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

Sidebar

Related Questions

I have a code below where it displays a text input in one column,
I'm a EE newbie. I have the code below. the poll weblog displays at
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have code that looks more or less like the code below but it
I have the code below. It looks long and complicated and now I have
I have the code below (I know this is only one function out of
Below is the code of a read only textbox: <td> <input type=text name=numberAnswer class=numberAnswerTxt
I have tried using the code below but it only display results in Chrome
I have code as below: var s : String = hello world var xml
I have the code below. void *timer1_function(void * eit); pthread_t timer1; int thread_check1 =

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.