javascriptjqueryspringsource

How to avoid getting the extra special character at the initial text box while using the jquery map function -join(/)


i have the below javascript function.

           function formsubmit()
            {
              var missedReasonCode =$('input[name*="MissedReasonCode"]').map(function()     
           {return $(this.id).val();}).get().join("/") ;
              $("#reasonValue").val(missedReasonCode); 
         alert($("#reasonValue").val());--able to get the list of values as in the format say /a/b/c  
            document.getElementById("frm1").submit();
                  }

        ***and the below is the part of the jsp page code:***


                <form:textarea path="reasonValue"  id="reasonValue" cssClass="textbox width100" cssStyle="visibility:hidden"></form:textarea>                

                </form:form>

             <div id="mask" style="display: none;"></div>

            <div id="adddelTBSec" class="adddelTBSection" style="display: none;">
          <div class="line marT20">Missed Reason Code</div>
         <div class="line">


             <div class="unit width60 padR10 boxSizing marT5">

             <input type="text"  name="MissedReasonCode" maxlength="150" size="50"               value="" class="padR10 boxSizing"/>

                   </div>

      <div class="unit icoPlus marT5" onclick="adddelTBSection(this,   'adddelTBContainer',1)"></div>
    <div class="unit marL10 icoMinus marT5" onclick="adddelTBSection(this,   'adddelTBContainer', 0)"></div>
</div>
             </div>



                 <div id="addNewMisdReasonCode" class="ltBox" style="display: none;">
             <div>
                <div class="ltBoxHdr">
                  Add New "Missed Reason Codes"
                  </div>
             <div class="ltBoxContent" style=" width: 640px;">
                    <div id="adddelTBContainer" style="maxheight:200px;overflow:auto;">  
                        <div>
                          <div class="line">Missed Reason Code</div>
                          <div class="line">


                    <div id="clear" class="unit width60 padR10 boxSizing marT5">
                     <input type="text"  name="MissedReasonCode"           value=""  maxlength="150" size="50"  class="padR10 boxSizing"/>
                    </div>
         <div class="unit icoPlus marT5" onclick="adddelTBSection(this, 'adddelTBContainer', 1)"></div>
                </div>
                </di v>
            < /div>

the code takes the list of values and saves into the database on form submit , i am able to get the list of values and save in the database something like this /a/b/c

but i want to get rid of this initial special character / ,any help is appreciated


Solution

  • You have to takeout the first "/" with .slice() this way:

    $("#reasonValue").val(missedReasonCode.slice(1));
    //--------------------^^^^^^^^^^^^^^^^^^^^^^^^^--try using this way
    

    From the docs:

    Given a jQuery object that represents a set of DOM elements, the .slice() method constructs a new jQuery object containing a subset of the elements specified by the start and, optionally, end argument. The supplied start index identifies the position of one of the elements in the set; if end is omitted, all elements after this one will be included in the result.