javascript - How to Use one function for input classes with diffrent id's -


i working on new project , have created search users can search app other users.

so have price input box , counter beside every user. problem changes value of price first user queried sql database.

i know because put id on price form field.

i don't know how to values other users after first 1 , don't know how write code without using 'get element id' .

i new javascript appreciated please.

thanks.

here's php , mysql code:

        $con = mysqli_connect("localhost","root","","testing");         $q = mysqli_query($con,"select * user");         while($row = mysqli_fetch_assoc($q)){              if($row['image'] == ""){                 echo "<span class = 'userpic'><img width='100' height='100' src='images/verify.jpg' alt='default profile pic'> </span>";             } else {                 echo "<span class = 'userpic'><img width='100' height='100' src='images/".$row['image']."' alt='profile pic'</span>";             }               echo "                   <span class = 'username'>".$row['username']."</span>                   <form name = 'matchcreator' class = 'amount' action='arena.php' method ='post'>                   <input class='price' textarea class='price-box' type='text' id='price1' name='price' size='1' maxlength = '15' value='0'/>                   <button class='up' type ='button' onclick='incrementvalue();'><img src='images/up.png'  width='10px' height='10px' href='#'> </button>                   <button class='down' type ='button' onclick='decreasevalue();' ><img src='images/down.png' width='10px' height='10px' href='#'></button>                   <div class = 'light'>                   </div>                   <div class = 'light2'>                   </div>                   <div class = 'light3'>                   </div>                   <div class = 'light4'>                   </div>                   <div class = 'light5'>                   </div>                   <button class='send' type = 'submit' onclicl=onclick='return confirm('are sure?')'>send challenge</button>                   </form>                    ";                            echo "<br>";         }             ?> 

here's javascript :

         function  incrementvalue()           {       var value = parseint(document.getelementbyid('price1').value, 0);       value = isnan(value) ? 0 : value;       value++;       document.getelementbyid('price1').value = value;       }       function decreasevalue()       {       var value = parseint(document.getelementbyid('price1').value, 0);       value = isnan(value) ? 0 : value;       value--;       document.getelementbyid('price1').value = value;       } 

please kindly me out

i recommend using jquery if you're not experienced java script.

with jquery accomplished doing:

<!doctype html> <html lang="en"> <head>   <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <body>   <input class='price' textarea class='price-box' type='text' id='price1' name='price' size='1' maxlength = '15' value='0'/>   <button class='up' type ='button' onclick='change();'>   <button class='down' type ='button' onclick='change();'>   <script>     function change(){       var text = $(".price").text();       alert(text + " " + $.isnumeric(text));     }   </script> </body> </html> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -