Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update hidden input field value with another input field value?

I am trying to update one hidden input field with another visible input field using javascript...

but my code doesn't work for some reason!!

This is my javascript:

<script language="javascript">
    function process1() {
        document.getElementById("sum_total").value = (document.getElementById("my-item-price").value);
    }
</script>

And This Is My form code:

<form><input name="A1" type="text" class="A1" id="A1"/></form>

<form><input type="hidden" id="A2" name="A2" value="process1() "/></form>

Update

<script language="javascript"> 
    function process1() { 
        document.getElementById("sum_total").value = (document.getElementById("my-item-price").value); 
    } 
</script>
like image 292
Rooz Far Avatar asked Feb 05 '13 14:02

Rooz Far


People also ask

How do I add multiple values to a hidden field?

Use indexOf() into value string, searching for the desired key to find a starting position. Then remove the chars between starting position plus the lenght of key.

How do you pass an input hidden array?

If you want to post an array you must use another notation: foreach ($postvalue as $value){ <input type="hidden" name="result[]" value="$value."> } Save this answer.


1 Answers

The code you have is bad. You haven´t got ids you are looking for in javascript.

Try this:

 <script language="javascript">
 function process1(showed) {
    document.getElementById("A2").value = showed.value;
}
</script>

<form><input name="A1" type="text" class="A1" onChange="process1(this)"/></form>

<form><input type="hidden" id="A2" name="A2" value="5" /></form>
like image 193
Tomas Nekvinda Avatar answered Oct 02 '22 18:10

Tomas Nekvinda