Dynamically change Input name with multiple dimensional array - Javascript jQuery

Javascript examples for jQuery:Array

Description

Dynamically change Input name with multiple dimensional array

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.js"></script> 
  <script type="text/javascript">
    $(function(){/*from www.  ja  v  a2s  . c  o m*/
$('input').attr('name',$('input').attr('name').replace(/\[\d+](?!.*\[\d)/, '[1]'))
console.log($('input').attr('name'));
    });

      </script> 
 </head> 
 <body> 
  <input id="abc" type="hidden" name="myInput[1][sausages][0][]" value="123">  
 </body>
</html>

Related Tutorials