admin管理员组文章数量:1327094
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
3 Answers
Reset to default 2Try 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.
本文标签: javascriptPass input textbox value in onClick functionphpStack Overflow
版权声明:本文标题:javascript - Pass input textbox value in onClick function - php - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742207638a2433115.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论