last day (15 days later) » 

4:33 PM
1
A: After ajax rerun php

Tony SamperiThe only way is making a PHP page that does the calculation HTML/page1.php <select id="option" name="option"> <option value="15">15</option> <option value="30">30</option> <option value="90">90</option> </select> <div id="dynamic"> <p>DEFAULT CONTENT</p> </div> HTML/page2.php ...

 
Ria
Thanks for you reply, the problem is it is all echoed back as in a div, what I wanted is just to use the posted value of the option. Do you know if that is possible at all
 
I made some adjustments. Check'em out please. Anyway the only way to do what you ask is this way.
Unless you make page2.php echo JSON data and use it
 
Ria
Would I still have to do this in a div or can I just recall $_POST['option'] its just I wanted to display the calculated values at several places and use them in different ways depending on the value chosen. Sorry to be a pain
 
With JSON you have much more freedom...
 
Ria
would you be able to show me as I haven't got a clue where to start or point me in the right direction. Thanks again so much
 
4:33 PM
check out the updated answer
 
Ria
so sorry I can't get that to work. I made a new page as suggest and used the exact code as you described option value X 2. There fore I was hoping to echo out in the page <?php echo $_GET['option'] ?> however i for no response. Thanks for you help
 
press F12 and check if the console shows any error
 
4:49 PM
I updated the answer, try the mods please
 
Ria
5:11 PM
Sorry no error showing (on Mac) also no joy echoing the $_POST['option']
 
You should use $_GET
Anyway if you use Chrome on Mac there must be a way to open the inspector
 
Ria
TypeError: $('#option').on is not a function. (In '$('#option').on', '$('#option').on' is undefined)
I changed the select div to option I didn't think that should make any difference
so the script is :<script type="text/javascript">
$('#option').on("change", function() {
var selected = $(this).val();
$.get("page2.php?option=" + selected, function(response) {
//do stuff with data
console.debug("RESPONSE", response);
});
});
</script
I also changed the $_POST['option'] to $_GET['option'], still no joy
 
5:28 PM
I need to see also the HTML
Wrap the $("#option").on with $(document).ready()
 
Ria
TypeError: $('#option').on is not a function. (In '$('#option').on', '$('#option').on' is undefined) and the script was changed to <script type="text/javascript">
$(document).ready()
$('#option').on("change", function() {
var selected = $(this).val();
$.get("/page2.php?option=" + selected, function(response) {
//do stuff with data
console.debug("RESPONSE", response);
});
});
</script> hope Ive done that right
 
Ria
5:51 PM
I left the html unchanged
<script type="text/javascript">
$(document).ready(function(){
$('#option').on("change", function() {
var selected = $(this).val();
$.get("/page2.php?option=" + this.val, function(response) {
//do stuff with data
console.debug("RESPONSE", response);
});
});
});
</script>
this gave me the same error. Sorry if this is not what you wanted
 
$.get("/page2.php?option=" + selected, function(response) {
 
Ria
sorry changed that back, still no joy. the only thing I could think of is that the on change function is wrong as it said in the type error $('#option').on is not a function, but I really don't know
 
6:08 PM
it must work. It's correct as you can see in my fiddle. https://jsfiddle.net/tonysamperi/4dbwwn3g/.
Please copy EXACTLY what is written there
 
Ria
Sorry your fiddle does work, the thing I wanted was to use the $_GET['option'] not in a div. Do you know if that is possible but outside the div and on different places in the page
 
Let's do this: do you have team viewer?
I must see everything that you have written and I cannot help you like this
You're too inexperienced
 

  last day (15 days later) »