J
J
Jony13372016-07-10 18:11:54
PHP
Jony1337, 2016-07-10 18:11:54

Is it possible to pass a variable from js via POST?

There is a bootstrap 3 template, there is such a cool thing in javascript, here is a screen prntscr.com/br4sui
and the code for this beauty

function validateForm() {
    var x = document.forms["myForm"]["options"].value;
    if (x == null || x == "") {
        swal({   title: "Errors!",   text: "Nu ai ales nici un raspuns la prima intrebare !",   imageUrl: "images/thumbs-up.jpg" });
        return false;
    }
  var y = document.forms["myForm"]["optionsx"].value;
  if (y == null || y == "") {
        swal({   title: "Errors!",   text: "Nu ai ales nici un raspuns la a 2 intrebare !",   imageUrl: "images/thumbs-up.jpg" });
    
        return false;
           
    }
  else {
    
  
      swal({   title: "An input!",   
    text: "Write something interesting:",   
    type: "input",   
    showCancelButton: true,   
    closeOnConfirm: false,   
    animation: "slide-from-top",   
    inputPlaceholder: "Write something" }, 
    function (inputValue) {   
    if (inputValue === false) return false;      
    if (inputValue === "") {     
    swal.showInputError("You need to write something!");     
    return false   
    }      
    swal("Nice!", "You wrote: " + inputValue, "success"); });
  }

}

But as you can see there and there is a check, the point is that after clicking on the submit button, the code displays the form for the name input, but it quickly disappears and redirects to the load.php file didn't rethrow and how to pass inputValue from js to php to file load.php
May the force be with you!
ps1. here is the submit code
<form method="POST" name="myForm" onsubmit="return validateForm()" action=" " >
  <div class="btn-group" data-toggle="buttons">
    <label class="btn btn-primary">
      <input name="options" id="option1" type="radio"> Da !
    </label>
    <label class="btn btn-primary">
      <input name="options" id="option2" type="radio"> Nu ! 
    </label>
    <label class="btn btn-primary ">
      <input name="options" id="option3" type="radio"> 50 la 50
    </label>
  </div> 
  
    <h3>Cind vezi o masina veche ai vrea sa faci un cerc la volan ?! (numa o varianta de raspuns)</h3>
  
  <div class="btn-group" data-toggle="buttons">
    <label class="btn btn-primary">
      <input name="optionsx" id="option4" type="radio"> Da !
    </label>
    <label class="btn btn-primary">
      <input name="optionsx" id="option5" type="radio"> Nu !
    </label>
    <label class="btn btn-primary ">
      <input name="optionsx" id="option6" type="radio"> 50 la 50
    </label>
  </div>

 <input type="submit"  value=Afla!>
 </form>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question