Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP变量传递给javascript/jquery进行错误检查_Javascript_Php_Jquery_Variables - Fatal编程技术网

将PHP变量传递给javascript/jquery进行错误检查

将PHP变量传递给javascript/jquery进行错误检查,javascript,php,jquery,variables,Javascript,Php,Jquery,Variables,看到了其他类似的例子,但我似乎仍然有问题。问题在于下面第三个错误检查器的脚本(#bid

看到了其他类似的例子,但我似乎仍然有问题。问题在于下面第三个错误检查器的脚本(#bid<#budm)。bid字段的金额不能低于设置预算的金额,budm应存储该预算。使用php从与post id相关的数据库中提取#budm的值。试图将该变量传递到js错误检查器,该检查器将存储php变量的隐藏输入字段(id=“budm”)与用户输入的输入字段(id=“bid”)进行比较。似乎是随机的。例如,在一个$budgetmin值为400的帖子上,400以下的大多数条目都不被接受(这很好),但出于某种原因,值“9”被拒绝了

<?php
global $current_user;
get_currentuserinfo();
$cid = $current_user->ID;
$cwd = str_replace('wp-admin','',getcwd());
$post = get_post($pid);
$budgetmin = get_post_meta($pid, 'budget_start', true); ?>

<input type="hidden" id="budm" value="<?php echo $budgetmin; ?>">

<script type="text/javascript">

function check_submits()
{

if( jQuery("#days_done").val().length == 0 ) 
{
    alert("<?php _e('Error text3'); ?>");
    return false;   
}

if( jQuery("#bid").val().length == 0 ) 
{
    alert("<?php _e('Error text2'); ?>");
    return false;   
}

if (jQuery('#bid').val() < jQuery('#budm').val()) 
{
     alert("<?php _e('Error text'); ?>");
     return false;
}

return true;
}


</script>

<input type="text" name="bid" id="bid" class="bid_field" value="<?php echo     $bid; ?>" size="10" /> 

<input class="green_btn grey" style="font-size: 20px; padding-left: 15px; padding-right: 15px; font-weight: 400;" id="submits_crt" type="submit" name="bid_now_reverse" value="<?php echo "Submit"; ?>" />


问题是
.val()
返回的是字符串,而不是数字。测试是将这两个值作为字符串进行比较,这不是您想要的,也不符合您的预期

在测试开始之前,您需要将您的值转换为数字。如果你知道它们总是整数,你可以使用:

var bid=parseInt(jQuery('#bid').val()),
    budm=parseInt(jQuery('#budm').val());

if (bid < budm) {
    alert("Bid is lower than budget");
}
var bid=parseInt(jQuery('#bid').val()),
budm=parseInt(jQuery('#budm').val());
如果(投标
如果输入可以是浮点,则可以使用parseFloat()


.

首先,检查浏览器控制台是否有任何错误。然后检查jQuery是否在无冲突模式下使用。好吧,你说这有问题,但是当你运行代码时会发生什么?谢谢你的回复!所以…-$budgetmin=100-用户在#投标输入字段中输入10-错误检查正确运行-然后用户将50的金额重新提交到#出价-错误检查失败,50的值除外。@RyanVollmer您的意思是“接受50的值”吗?正如dekkard所建议的,检查控制台是否有错误。张贴正在提交的投标代码。是,已接受。这显然太早了。将尽快在此处发布控制台代码。:)谢谢我一到家就试试这个!谢谢大家!-兰特非常感谢你的帮助!!这个解决方案奏效了。我非常感激!!