I have found Javascript to be the most difficult language to find useful and CORRECT info on. Afterr working for several hours looking at various sites, I'm still somewhat stumped.

All I know at this point is that these is a difference in the array formatting between PHP and JS. The magic bullet is supposed to be json.
However, this code does not work as advertised.

javascrript snippet:
var pt = <?PHP json_encode($prt); ?>

The variable $prt is list of associative arrays, so to get a value in a particular row manually , $prt[0] should give me the value for location in the first row of output.
All of this works just fine if i hard code this in html and php.
However, I want to dynamically produce the rows as needed which requires that a loop employed. The application also requires that the user may add a row which also need to be accounted for when posting.
After many experiments, I think the best solution is to make this a totally javascript entity .All I need to do is to be able to pass in the server side data. Calling JS from PHP does not work, although i have found many places where they show basically the same code , claiming that it works.

I think json needs a bit of tweaking to make this happen, but i'm not sure how to proceed.

You forgot the echo

vart pt = <?php echo json_encode($prt); ?>

You forgot the echo

vart pt = <?php echo json_encode($prt); ?>

Yes, I tried echo, but that doesn't work either. PHP does "flatten" the array into a string when I do a var_dump(). However JS does not accept it into the variable.
In fact any attempt to populate the variable on that line crashed the script.
Remove the line and the rest of it works again.
I can't seem to retrieve values via the DOM when I tried that by dumping a value into a hidden input, then pulling it from there.

JS is making me crazy.
I don't have any debug set up for JS at this time which makes it even worse.
All in all I think it's my overall lack of knowlege about JS that is sinking me.

AHa! I tested what I was convinced would work on a remote JS sandbox in W3 and it works there, but not in my IDE.

Now I'm in the process of updating the IDE. hopefully this is some bug that got fixed along the way.

Isn't programming grand? A gotcha around every corner!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.