1

this is the code i tried:

function show(date,meal){
var parameters = 'q='+date '&m='+meal;
var argUrl = 'meal1.php';
    $.ajax({
        url: argUrl,
          type: 'POST',
          data: parameters,
          success: function (str) {
          $('#txtHint').html(str);  
          //alert(parameters);              
         } 
    });
 }

My form:

<form method="post">
<input type="text" id="datewise" name="datewise"  value="" class="form- control input-datepicker-close"  placeholder="dd/mm/yy" >

<select id="mealplan" name="mealplan" class="form-control" onchange="shownoofroom(this.value);">
<option value=""> Select </option>
    <?php  $sql = "select *from mean_plan";
    $retval = mysql_query( $sql, $conn );
    if(! $retval ){
      die('Could not get data: ' . mysql_error());
      echo 'Could not get data: ' . mysql_error();
     }
      while($row = mysql_fetch_array($retval,MYSQL_ASSOC)){ //roll id if
     //$roll_id= $row['roleid'];
  ?>
  <option value="<?php echo $row['meanplan']?>"><?php echo $row['meanplan']?></option>

  <?php
   }
    ?>
 </select>

<input type="buttton" class="btn btn-info btn-primary " onclick="show('<?php $_POST['datewise'];?>','<?php $_POST['mealplan'];?>')name="submit">
</form>
<div id="txtHint">

Is this the correct method to pass parameters to a function.. Or else how i can pass form values in the onclick event and store it in function variable.

3
  • 1
    it'll be easier if you use jQuery. .serialize() will get all values on your form Commented May 20, 2015 at 11:01
  • Am i right in onclick() part..... Commented May 20, 2015 at 11:02
  • i'm getting an error message Commented May 20, 2015 at 12:10

1 Answer 1

2

this is ok

function show(date,meal){

var argUrl = 'meal1.php';
    $.ajax({
        url: argUrl,
          type: 'POST',
          data: {
                    date:date,
                    meal:meal
                     },
          success: function (str) {
          $('#txtHint').html(str);  
          //alert(parameters);              
         } 
    });
 }
Sign up to request clarification or add additional context in comments.

8 Comments

what about the button call...onclick=show('<?php $_POST['val1']?>','<?php $_POST['val2']?>')
show('<?php echo $_POST['val1']?>','<?php echo $_POST['val2']?>')
is it right to call a function in this manner
i'm getting an error as undefined index $datewise,$mealplan in onclick=show('<?php $_POST['datewise']','<?php $_POST['mealplan']')
first change show('<?php $_POST['datewise']','<?php $_POST['mealplan']') to show('<?php echo $_POST['datewise']','<?php echo $_POST['mealplan']') and than check
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.