1

I have the following Javascript to generate a silent call to another sheet to update a database value without refreshing the page

function UpdateDB(table,column,type){
    var value = $("#Assigned").val();

    $.post("UpdateValuation.php?Table=" + table + "&Value=" + value + "&Column=" + column + "&Type=" + type, {}).done();
};

This works perfectly but only for the "Assigned" table row since it is statically assigned.

I use the following php to generate the table entry with button

print "<tr><td>" . $stuff['Status'] . "</td><td ><input type=\"text\" id=\"" . $stuff['Status'] . "\" name=\"" . $stuff['Status'] . "\" value=". $stuff['Value'] ." size = \"4\" style = \"text-align: center\"/><button onclick=\"UpdateDB('NOCstatus','Status','". $stuff['Status'] ."');\">Update</button></td></tr>";

Which after variables are assigned looks like this for my "Pending" row

<input id="Pending" type="text" style="text-align: center" size="4" value="120" name="Pending">    </input>
<button onclick="UpdateDB('NOCstatus','Status','Pending');">
Update
</button>

My problem is that passing "this.value" or trying to use a variable in the javascript portion I always come up with a blank value, the only time I can get a value to be correct is by statically assigning the "#Assigned" or "#Pending" in the value field. I have hundreds of entries so I don't want to write the function over for each of these. I know there is probably something extremely simple I am missing but I cannot get the pieces to fit.

I need to pass the typed in value in the input field to the function to update the database. Please help.

1
  • Not sure if i understand but this.value will not get set in your code because the id is "Pending" when your php is generating it. Commented Sep 18, 2014 at 19:56

1 Answer 1

3
function UpdateDB(table,column,type){
    var value = $('#'+type).val();

    $.post("UpdateValuation.php?Table=" + table + "&Value=" + value + "&Column=" + column + "&Type=" + type, {}).done();
};    

?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is it. I had tried it previously but with double quotes and it did not work. I knew it was something simple. Thank you, I will accept answer in a few minutes when it is available.

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.