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 $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'] ?>')">

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

Matarishvan
  • 2,382
  • 3
  • 38
  • 68
  • http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – Dan Smith Feb 25 '15 at 11:39

3 Answers3

2

Try this:

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value);">
Ataboy Josef
  • 2,087
  • 3
  • 22
  • 27
1

Have you tried writing something like following.

<input type="submit" value="submit" onclick="saveValue(document.getElementById('acre_value').value)">
Nirav Kamani
  • 3,192
  • 7
  • 39
  • 68
1

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.

GuiPab
  • 455
  • 2
  • 7
  • 18