-1

How can I take the value of:

<span name="MinPrice" class="irs-from">0</span> <span name="MaxPrice" class="irs-to">0</span> 

And assign them to PHP variables:

$MinPrice $MaxPrice 

This is my JQuery code:

 var base_html = '<span class="irs">' + '<span class="irs-line" tabindex="-1"><span class="irs-line-left"></span><span class="irs-line-mid"></span><span class="irs-line-right"></span></span>' + '<span class="irs-min">0</span><span class="irs-max">1</span>' + '<span name="MinPrice" class="irs-from">0</span><span name="MaxPrice" class="irs-to">0</span><span class="irs-single">0</span>' + '</span>' + '<span class="irs-grid"></span>' + '<span class="irs-bar"></span>'; 

I use form:

<form action="<?php echo languageURL(0, ''.$g['url'].'products.html'); ?>" method="get"> <div class="wrapper" style=" padding:20px;"> <div class="range-slider"> <input type="text" class="js-range-slider" value="" /> </div> </div> <input type="submit" class="btn-primary goo" value="Търсене" /> </form> 
8
  • 3
    If you want to put values of client-side elements in to PHP you will need to send a request to the server, either via a form or through AJAX. Also note that span elements don't have values, they have innerText/Html Commented Dec 19, 2018 at 12:06
  • You need to send the values via ajax Commented Dec 19, 2018 at 12:06
  • 3
    And not many of us are going to WADE THRU 100's of lines of code looking for SOMETHING... who knows what. Commented Dec 19, 2018 at 12:07
  • NB Php will not execute on your products page. the page is a .html ext it must be a .php file Commented Dec 19, 2018 at 12:10
  • I fixed the post. Sorry ! Commented Dec 19, 2018 at 12:11

2 Answers 2

0

You could use AJAX to assign your values to PHP variables. You can send the form data like this in jQuery:

function sendData() { $.ajax({ type: "POST", url: 'ajax.php', data: {$("#formID").serialize(), MinPrice: $('#minSpan span').html(), MaxPrice: $('#maxSpan span').html()}, dataType: "html", success: function(html) { // do something ... } }); } 

In this case the data is sent via POST and your form needs an ID (e.g. id="formID").

Update: Now also the values of the spans are sent, here with the IDs id="minSpan" and id="maxSpan". In ajax.php you can read the POST values, try it with to see all available values:

var_dump($_POST); 
Sign up to request clarification or add additional context in comments.

4 Comments

Ok, but how to send the information exactly to the php form:
I updated my post
Hello ! Thank you ! When I try to enter it into the body of the code, the code crashes.
I try this: $(function () { $.ajax({ type: "POST", url: "../include/aside.php", data: {$("#filter").serialize(), MinPrice: $("#minSpan span").html(), MaxPrice: $("#maxSpan span").html()}, dataType: "html", success: function(html) { alert(html); } }); });
0

As already mentioned in comments

  1. Span doesn't have values they have innerHTML.
  2. You will need to do it through ajax(if you want to do it using jQuery).

Now To get the value out of base_html variable, you will first need to parse HTML string and then take out values from it i.e.

var min = $.parseHTML( base_html).find(".irs-from").text(); var max = $.parseHTML( base_html).find(".irs-to").text(); $.ajax({url: "value_set.php?min="+min+"max="+max, success: function(result){ //do whatever you like to do here }}); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.