0

I am trying to build a table using PHP and SQL values. One of those table columns is going to have a numerical input that controls other values in that row. This parameter ranges from 0 to 1 and I'm trying to use Javascript to dynamically update the three columns to the right of it depending on the parameter value.

Here is the PHP commands for the html table:

$i = 1;
while($row = mysql_fetch_array($result)){
    Print "<tr>"; 
    Print "<td><input id='toChange[$i]' name='toChange[$i]' type='number' step='0.01'   
    min='0.01' max='0.99' value='.85' </td>";
    Print "<td>".$row['dependentOnParameter1'] . "</td>";
    Print "<td>".$row['dependentOnParameter2'] . "</td></tr>";
$i++;

}

I have tried many different tags for the input cell, such as toChange[] and toChange$i (this one as if the number grows with the row number). This table prints correctly, and here is the jQuery function I have tried to implement:

$('#prEff[1]').change(function() {

    var test = this;
    return;
});

I know how to alter the table once I get this function to correctly call, but the use of an input inside an array seems to be causing trouble. Is there a specific jQuery object or tag that must be used for .change for arrays? Or if I can use the table tag, will the this pointer point to the part of the table that has been altered?

1 Answer 1

1

You probably need to escape the brackets if they are part of the selector:

$('#prEff\\[1\\]')
Sign up to request clarification or add additional context in comments.

2 Comments

is there anyway to generalize the jquery function for all the possible values inside the brackets? So, #prEff\[VariableIndex\]' for example? So i don't have to repeat jquery functions?
Sure $('[id^="prEff["]'), the attributes starts with selector!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.