0

Given that PHP is server-side, I have a question:

Within a php file, I have some HTML with a function declared like so:

<div class="img_div" ng-click="swipeUrl(variable)>

<!--data pulled from SQL server-->

</div>

Inside ng-click="swipeUrl(variable)" there is a variable that I want to be dynamic. I could put '<?php .$param. ?>', but I wouldn't be able to change the PHP variable without AJAX, right?

Is it possible to put a javascript variable there that is dynamic (ie, fetch some data on a click and change this variable)? Maybe I could have an onClick function there, and then the script can be dynamic?

..or is the only way to make this work with an AJAX call?

rpivovar
  • 3,150
  • 13
  • 41
  • 79
  • Do you want the user to be able to pass some value to your php file, that is that when this file is being executed it returns the value in place for the variable, provided by the user? I.e. user perform some action and gets HTML where the value of the variable is the one provided by himself? – d.k May 23 '17 at 22:52
  • I'm trying to get an element's attribute on click, so I guess I could just have the PHP place an onClick and then the Javascript will do the rest? – rpivovar May 23 '17 at 22:56
  • Yes, exactly. On click, get element's ID and pass to a function. I actually think I can just do that with Javascript if the onClick is in the php – rpivovar May 23 '17 at 23:05
  • first, look at the referenced question, I'm sure it has several right answers. But generally, you have many approaches to do this, and I really cannot see any need for AJAX here. You could make your js-function to take the element's id. Or if you cannot modify it, you can create a wrapper function, which will take the id of the event target element and pass it to you `swipeUrl` function. You need to get the essential concepts of client and server programs and their interaction. If the referenced answer doesn't make this clear, try to find some blog posts on the topic. – d.k May 23 '17 at 23:12
  • Yes, someone linked to another Stack Overflow question that I hadn't seen before, but it was incredibly helpful. I think I understand now. – rpivovar May 23 '17 at 23:14
  • Sorry, this is all new to me and can get confusing. – rpivovar May 23 '17 at 23:15

0 Answers0