find and replace.

find and replace.

Hello Jquery Users.

I am new to Jquery and I am xcited about the power of jquery.

I am currently stuck in doing what could be a simple thing to do in Jquery - Find and replace.

I have a HTML code ( see below )

What I need to do is that I need to search for all any DOM element with name ( dynamicPollUrlList[2] ) and replace it with (dynamicPollUrlList[1]).

basically I want to reduce the index 2 to 1.

HTML code
  <tr id="multiPollRow[0]">
         <td>
           <input name="dynamicPollUrlList[2].urlID" type="hidden" value="2"/>
          
           <select name="dynamicPollUrlList[2].pollID"><option value="186">NewPollMultiQuestion</option><option value="187">NewPOllEst</option><option value="157">TestAug26</option><option value="173">TestExpireSoon</option><option value="167">new_new_TestAig26</option></select>            
          
          </td>

          <td >
          <input id="dynamicPollUrlList0.strRedirectUrl" name="dynamicPollUrlList[2].strRedirectUrl" type="text" value="" size="25"/>
          </td>
         
         
          <!-- Start date , time and timezone -->
         <td >
          <input id="publishStartTime" name="dynamicPollUrlList[2].startDateTimeTimezone.strDate" type="text" value="09/28/2008 17:38:11" size="20"/>
         
          <select id="dynamicPollUrlList0.startDateTimeTimezone.timeZone" name="dynamicPollUrlList[2].startDateTimeTimezone.timeZone"><option value="America/Los_Angeles" selected="selected">PST</option><option value="America/New_York">EST</option><option value="America/Denver">MST</option><option value="America/Chicago">CST</option></select>

          </td>
         
          <!-- End date , time and timezone -->
          <td >
          <input id="publishEndTime" name="dynamicPollUrlList[2].endDateTimeTimezone.strDate" type="text" value="10/05/2008 17:38:11" size="20"/>
          <select id="dynamicPollUrlList0.endDateTimeTimezone.timeZone" name="dynamicPollUrlList[2].endDateTimeTimezone.timeZone"><option value="America/Los_Angeles" selected="selected">PST</option><option value="America/New_York">EST</option><option value="America/Denver">MST</option><option value="America/Chicago">CST</option></select>
          </td>
         
          <!-- Sponsored poll -->

          <td >
          <input id="dynamicPollUrlList[0].sponsored1" name="dynamicPollUrlList[2].sponsored" type="checkbox" value="true"/><input type="hidden" name="_dynamicPollUrlList[0].sponsored" value="on"/>
          </td>
         
         </tr>
         <tr>
           <td colspan="4">
              <div class="sm">* if you specify an End Date and time, no other poll can be published to this page until AFTER specified end date and time.</div>
           </td>

         </tr>


Here is the juqery code that I have written. But its long and all the names are hard coded.

what I want to do is - find all the elements with name ( dynamicPollUrlList[2] ) and replace it with (dynamicPollUrlList[1])

Now I am able to do the find part. But I need some help in doing the replace part.


jQuery Code

function reorderPollSched(tbl,index){

   var newIndex = parseInt(index) - 1;
   
   
   
   $("*[@name^='dynamicPollUrlList["+index+"]']").each(
      function(i){
         if(this.name == 'dynamicPollUrlList['+index+'].urlID'){
           this.name = 'dynamicPollUrlList['+newIndex+'].urlID'
         }else if(this.name == 'dynamicPollUrlList['+index+'].pollID'){
            this.name = 'dynamicPollUrlList['+newIndex+'].pollID'
            this.id = 'dynamicPollUrlList'+newIndex+'.pollID'
         }else if(this.name == 'dynamicPollUrlList['+index+'].strRedirectUrl'){
            this.name = 'dynamicPollUrlList['+newIndex+'].strRedirectUrl'
            this.id = 'dynamicPollUrlList'+newIndex+'.strRedirectUrl'
         }else if(this.name == 'dynamicPollUrlList['+index+'].startDateTimeTimezone.strDate'){
            this.name = 'dynamicPollUrlList['+newIndex+'].startDateTimeTimezone.strDate'
            this.id = 'dynamicPollUrlList'+newIndex+'.startDateTimeTimezone.strDate'
         }else if(this.name == 'dynamicPollUrlList['+index+'].startDateTimeTimezone.timeZone'){
            this.name = 'dynamicPollUrlList['+newIndex+'].startDateTimeTimezone.timeZone'
            this.id = 'dynamicPollUrlList'+newIndex+'.startDateTimeTimezone.timeZone'
         }else if(this.name == 'dynamicPollUrlList['+index+'].endDateTimeTimezone.strDate'){
            this.name = 'dynamicPollUrlList['+newIndex+'].endDateTimeTimezone.strDate'
            this.id = 'dynamicPollUrlList'+newIndex+'.endDateTimeTimezone.strDate'
         }else if(this.name == 'dynamicPollUrlList['+index+'].endDateTimeTimezone.timeZone'){
            this.name = 'dynamicPollUrlList['+newIndex+'].endDateTimeTimezone.timeZone'
            this.id = 'dynamicPollUrlList'+newIndex+'.endDateTimeTimezone.timeZone'
         }else if(this.name == 'dynamicPollUrlList['+index+'].sponsored'){
            this.name = 'dynamicPollUrlList['+newIndex+'].sponsored'
            this.id = 'dynamicPollUrlList'+newIndex+'.sponsored'
         }
      });
   
   
   
   
}



Any help is much appreciated.

Thanks!