最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pass input textbox value in onClick function - php - Stack Overflow

programmeradmin7浏览0评论

I have a input text field. I need to pass the values entered inside the element through onClick of javascript.

<form>
<fieldset>     
  <label>Common Site ID: </label><span><?php echo $monsiteid ?></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'] ?>')">

I am passing the value through submit onClick, Which is going empty. How do i pass value in this onclick function.

I have a input text field. I need to pass the values entered inside the element through onClick of javascript.

<form>
<fieldset>     
  <label>Common Site ID: </label><span><?php echo $monsiteid ?></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'] ?>')">

I am passing the value through submit onClick, Which is going empty. How do i pass value in this onclick function.

Share Improve this question asked Feb 25, 2015 at 11:37 MatarishvanMatarishvan 2,4323 gold badges42 silver badges70 bronze badges 1
  • stackoverflow./questions/13840429/… – Dan Smith Commented Feb 25, 2015 at 11:39
Add a ment  | 

3 Answers 3

Reset to default 2

Try this:

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

Have you tried writing something like following.

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

I try this, and worked:

<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>

As you can see, i pass the value by a hidden field, and on the Js function i get the value of this field.
If you need a php function instead off a js, it's the same logic.

发布评论

评论列表(0)

  1. 暂无评论