2016-11-04 27 views
-1

它怎么可能得到jQuery的变量值PHP变量如何获得jQuery变量值的PHP变量选择变化事件没有Ajax?

我的jQuery代码

jQuery(document).ready(function(){     

     jQuery("#mec_make").change(function(){ 
     jQuery("#frame").html(''); 

     makeval = jQuery(this).val(); 
     jQuery("#sec").val(makeval); 
    }); 

}); 
</scipt> 

HTML

<input type="hidden" name="te" value="" id="sec"> 

我会尽量在我的PHP得到jQuery的价值代码,但我不能得到它。

PHP

echo $year = '<script>jquery("#sec").val()</script>'; 
echo $year = '<script>document.write(document.getElementById("sec").value)</script>'; 

我不需要AJAX我希望它没有Ajax,我需要它的时候改变事件火灾值将存储到PHP变量。

全码

<div class="mak" id="mmm"><input type="hidden" name="te" value="" id="sec"></div> 

<?php 

echo "buddy".$year = '<script>jQuery("#sec").val();</script>'; 

$get_recent = $wpdb->get_results("SELECT * FROM wp_make_details 
          WHERE post_id =".$post_id." 
          AND year =$year 
          AND make_name ='Yamaha' 
          "); 

foreach ($get_recent as $key => $rec_value) { 
      $rec_value_year_data[] = $rec_value->year; 
      $model_name['model_name'] = $rec_value->model_name; 
      $datarrr[] =$model_name; 
} 

?> 

<select name="mec_year" id="car_year_select"> 
      <?php 
      $post_id = get_the_ID(); 
      $inserted_year = get_post_meta($post_id,'year',true); 
       echo "<option value=".$inserted_year.">".$inserted_year."</option>"; ?> 
        <script> 
        jQuery(document).ready(function(){ 
         jQuery("#mec_make").change(function(){ 
          jQuery("#frame").html(''); 
          makeval = jQuery(this).val(); 
          jQuery("#sec").val(makeval); 
         }); 
       }); 
      </script> 
</select> 
+0

'echo $ year;'...... – devpro

+0

'echo'it在赋值之后,不在赋值期间。 – Natrium

+0

@Natrium echoit分配后? – maddy

回答

1

如果你只想把mec_make价值为隐藏字段id="sec"比你为什么要使用PHP在这里,你可以得到所需的输出为:

jQuery(document).ready(function(){     
 

 
     jQuery("#mec_make").change(function(){ 
 
     jQuery("#frame").html(''); 
 

 
     makeval = jQuery(this).val(); 
 
     jQuery("#sec").val(makeval); 
 
     console.log(jQuery("#sec").val()) ; 
 
    }); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> 
 
<input type="hidden" name="te" value="" id="sec"> 
 
<select name="mec_make" id="mec_make"> 
 
    <option>Select</option> 
 
    <option value="1">My Value</option> 
 
</select>

另请注意,此</scipt>应该是</script>,修复错字。

现在,你如何获得在PHP中的值,简单的答案使用<form>和提交按钮,你会得到在PHP中的值。

+0

因为我需要在我的SQL查询中的值,所以我想在PHP变量中存储该值。 – maddy

+0

@maddy:是的,现在你可以在这里使用

,你会在PHP中获得所有的值,你可以在你使用它们查询 – devpro

+0

好吧,我已经使用表单,但我希望它没有提交 – maddy