For quite some time, whenever I needed to pass something like a database table row index from a webpage to a PHP script I would do string manipulation to get the data.
Something like this:
<div class="tdiv" id="td_4932">Something interesting</div> <script> var tid=this.id; tid = tid.replace('td_',''); //now tid = the index </script>
In an epic /facepalm moment I realized that I’ve been doing it the hard way. I realized this when I had to pass several bits of information back to the PHP script. The string manipulation code would be kludgetastic.
It was simple. Put the parameter as a custom attribute!
<div class="tdiv" id="tdept" dept="4932">Something interesting</div> //the dept attribute points to the target department in the database <script> var tid = $('#tdept').attr('dept'); console.log("The dept index is " + tid); </script>