Home > DeveloperSection > Forums > Values of variables to add in an array after I click the submit button?
ben reitman
ben reitman

Total Post:96

Points:676
Posted on    October-22-2013 3:42 AM

 JQuery JQuery 
Ratings:


 1 Reply(s)
 997  View(s)
Rate this:

Placed a value in an array variable after clicking submit button and the submit button will the one to trigger the arrayholder.push().

Variables that should be added to the array are those buttons that is clicked.

JAVASCRIPT

<script type="text/javascript">

val1=0;

val2=0;

val3=0;

val4=0;

arrayholder=new Array();

$("#id1").click(function(){

val1=val1+1;

$("#status").html(val1);

});

$("#id2").click(function(){

val2=val2+1;

$("#status").html(val2);

});

$("#id3").click(function(){

val3=val3+1;

$("#status").html(val3);

});

$("#id4").click(function(){

val4=val4+1;

$("#status").html(val4);

});

</script>

HTML CODE

    <button id="id1">ADD Val1 FROM id1</button>

    <button id="id2">ADD Val1 FROM id2</button>

    <button id="id3">ADD Val1 FROM id3</button>

    <button id="id4">ADD Val1 FROM id4</button>

<div id="status"></div>

<input type="submit" />



Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    October-22-2013 3:57 AM

Instead of "submit" type, change into "button" type and then use below line of code:

<html>

<head>

    <script type="text/javascript">

        function pushMe() {

            arrayholder.push(val1);

            document.getElementById("form1").submit();

        }

    </script>

</head>

<body>

    <form id="form1">

    <input id="btnPushMe" type="button" click="pushMe" />

    </form>

</body>

</html>


Don't want to miss updates? Please click the below button!

Follow MindStick