0

I'm having some trouble passing the value of some HTML elements to PHP variable. I have a PHP web app where I give the users some drop down option. What I want to do is after the user has selected the option I give than to click on a button and make some calculations based on his/her selection.

I have tried using the POST and GET method but because I'm new to php I probably did it wrong. I also try with ids but no results.

Here is the HTML code The 1st dropdown menu :

<div>
   <select id="kleidwma" onchange="kleidwmata_change(this.value);kwdikos();ypsos();" 
       class="form-control selectpicker kleidwmata" data-size="10"  data- 
       style="btn-white" name="guard_kleidwmata" required  >

       <option value="" >&nbsp;</option>
       <option value="12">12 MS</option>
       <option value="14">14 KETE</option>
       <option value="15">15 ARRIKTON</option>
       <option value="16">16 KETE</option>
       <option value="22">22 KETE</option>
   </select>
</div>

The 2nd dropdown menu :

<div>
    <select id="sigkratisi" onchange="kwdikos()" name="sigkratisi" 
        class="form-control sigkratisi" required>

        <option value="" ></option>
    <option value="metalliki" >Μεταλλική</option>
    <option value="xilogonia" >Ξυλογωνία</option>
     </select>
</div>

Here is the button to be clicked after the selection has been made :

<div class="row" style="margin-top:20px; margin-left: 235px;">
    <div class="col-md-7">
    <input type="hidden" name="tmp_calculate" value="pending" />
    <button onclick="calculate()" type="button" class="btn btn-success" > 
    <?php echo "Υπολογισμός";?></button>
    </div> 
</div>

And finally here is the function that is called :

function calculate()
{
    $var1 =   sigkratisi;
    $var2 =   kleidwma;
        "code to be executed base on the var1 and var2"
}

I hope it's clear enough. Thanks in advance for your time

7
  • 2
    You can't pass data directly html to php. You have to call ajax get/post request from html to php. then php return calculated data to your ajax success method. after you can print your calculated data inside html. Commented Apr 24, 2019 at 8:15
  • Possible duplicate of What is the difference between client-side and server-side programming? Commented Apr 24, 2019 at 8:15
  • Possible duplicate of Get all variables sent with POST? Commented Apr 24, 2019 at 8:15
  • Any hint how may i achieve that or where to look, thanks Commented Apr 24, 2019 at 8:17
  • The answer depends on what you want to calculate once the user has selected the options. Is it just a basic calculation that could be completed client side, or are you using the information selected to get more information from a database etc? Your post doesn't make it clear. Commented Apr 24, 2019 at 8:19

1 Answer 1

3

you can use Forms

<form name="f" action="" method="POST">
<div>
<select id="kleidwma" name="variable" 
   class="form-control selectpicker kleidwmata" data-size="10"  data- 
   style="btn-white" name="guard_kleidwmata" required  >
   <option value="" >&nbsp;</option>
   <option value="12">12 MS</option>
   <option value="14">14 KETE</option>
   <option value="15">15 ARRIKTON</option>
   <option value="16">16 KETE</option>
   <option value="22">22 KETE</option>
</select>
<input type="submit" value="submit" />
</div>
</form>

in PHP

<?php
if(isset($_POST['variable']))
{
echo $_POST['variable'];
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.