简体   繁体   中英

passing parameter in function

I want to pass parameter in function Myfunction() .I want to pass 1) php value 2) this.value 3) document.getElementById("rec") in a same function. If I pass only this.value as parameter function called successfully and passed to jquery-ajax page but I have problem with passing three or two parameter at a time. If I tried to pass in action using jquery Its also not working. document.getElementById("rec") and var eid=$("#rec").val(); is not working.

echo '<form method="post">';
 $rec="select * from recruiter where comp_id='$comp'";
               $rec1=mysql_query($rec);

               echo '<select class="rec" id="rec" name="e_first_name" style="width:155px;" required onchange="myFunction(this.value);">';
               echo '<option value="" selected>Select Recruiter</option>';
               while($rfet=mysql_fetch_assoc($rec1))
               {
                 echo '<option value="'.$rfet["e_id"].'">'.$rfet["e_first_name"].'</option>';
               }
               echo '</select>';


               echo '<input type="text" name="dob" style="width:155px;display:none;"  id="datepicker1" placeholder="Choose Date" size=18 maxlength=50>';
               echo '<select name="report" style="width:155px;" class="report"  onchange="myFunction(this.value);">
               <option selected> Select Filter</option>
               <option value="datz">By Date</option>
               <option value="week">By week</option>
               <option value="month">By month</option>
               </select>';
               echo '</form>';
               ?>

My function as given below

function myFunction()
 {   
  $("#pre").hide();
  var datz=$("#datepicker1").val();

  var filt=$(".report").val();

   var eid=$("#rec").val();
    $.ajax({
        type: "POST",
        url: "query3.php",
        data: { action: eid,filter:filt,datz:datz},
        error: function(msg) {

        },
        success: function(text) {

            $(".refresh").html(text);          
        }
    });
    }

Add any parameter inside your function.

For example:

    function myFunction(a) {   

       $("#pre").hide();
       var datz=$("#datepicker1").val();
       var filt=$(".report").val();
       var eid=$("#rec").val();

        console.log(a + ' : ' datz + ' : ' + filt + ' : ' + eid);

          $.ajax({
            type: "POST",
            url: "query3.php",
            data: { action: eid,filter:filt,datz:datz},
          error: function(msg) {

          },
          success: function(text) {
             $(".refresh").html(text);          
         }
      });
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM