Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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
Javascript 在onClick函数-php中传递输入文本框值_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 在onClick函数-php中传递输入文本框值

Javascript 在onClick函数-php中传递输入文本框值,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一个输入文本字段。我需要通过javascript的onClick传递元素中输入的值 <form> <fieldset> <label>Common Site ID: </label><span><?php echo $commonsiteid ?></span><br> <label>Acres: </label><input id="acre_va

我有一个输入文本字段。我需要通过javascript的onClick传递元素中输入的值

<form>
<fieldset>     
  <label>Common Site ID: </label><span><?php echo $commonsiteid ?></span><br>
  <label>Acres: </label><input id="acre_value" name="acre_value" type="text" value="<?php echo $acre; ?>">
 </fieldset>
</form>
<input type="submit" value="submit" onclick="saveValue('<?php echo $_REQUEST['acre_value'] ?>')">

公共站点ID:

阿克斯:你有没有试过写下这样的东西

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value)">

您是否尝试过编写以下内容

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value)">

试试这个:

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value);">

试试这个:

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value);">

我尝试了这个,并成功地:

<script>
    function saveValue(){
        alert(document.formName.hiddenField.value);
        /*do something*/
        return false;
    }
</script>
<form name="formName" method="post">
    <input type="hidden" name="hiddenField" value="<?php echo $_REQUEST['acre_value'] ?>"/>
    <input type="submit" value="submit" onclick="saveValue()">
</form>

函数saveValue(){
警报(document.formName.hiddenField.value);
/*做点什么*/
返回false;
}

我尝试了这个,并且工作:

<script>
    function saveValue(){
        alert(document.formName.hiddenField.value);
        /*do something*/
        return false;
    }
</script>
<form name="formName" method="post">
    <input type="hidden" name="hiddenField" value="<?php echo $_REQUEST['acre_value'] ?>"/>
    <input type="submit" value="submit" onclick="saveValue()">
</form>

函数saveValue(){
警报(document.formName.hiddenField.value);
/*做点什么*/
返回false;
}