Javascript Replace()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • risk32
    New Member
    • Mar 2008
    • 98

    #16
    Ahhh... not again! There's a coding error in the JS portion. I dont have anything to debug it except notepad.

    Code:
    <html>
    
    <select id="selDay" >
    <option value="01">01</option>
    <option value="02">02</option>
    <option value="03">03</option>
    <option value="04">04</option>
    <option value="05">05</option>
    <option value="06">06</option>
    <option value="07">07</option>
    <option value="08">08</option>
    <option value="09">09</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
    
    <select id="selMonth">
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>
    
    <select id="selYear" >
    <option value="2008">2008</option>
    </select>
    <script type="text/javascript">
    function myFunction()
    {
    var str="";
    var selDay = document.getElementById("selDay");
    var selMonth = document.getElementById("selMonth");
    var selYear = document.getElementById("selYear");
    str = selDay + " " + selMonth + " " + selYear;
    linkRef.href = "\\yofs13\374OG\36AS\Asgard_data\data\Duty Desk\Electronic Boards Info\Schedule Slides\2008\" + str + ".ppt";
    }
    </script>
    <a href="javascript:myFunction();">Here is the slide</a>
    </html>

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #17
      Firstly, linkRef should be set to the link element whose href property needs changing. Also selDay, selMonth, etc. should be set the value of the select elements, not the elements themselves.

      Comment

      • risk32
        New Member
        • Mar 2008
        • 98

        #18
        So... I should set the option value to equal selDay, SelMonth, and selYear
        and linkRef.href = selDay + selMonth + selYear?

        Comment

        • Rsmastermind
          New Member
          • Sep 2008
          • 93

          #19
          hi
          what u can do is you can change the nodevalue in any function like this.....
          [HTML]<select .......
          onchange="chang eValue(this);" ...../select>
          [/HTML]
          <script type="text/javascript">
          [CODE=javascript]function changeValue(tha t){
          var linknode=$('ID of the hyperlink').;
          var combovalue=that .value;//Can get value in this way of the combo.

          linknode.firstC hild.nodeValue= 'as per your desired value you can use concatenation or indexOf() funcn to print value at desired place in the string';


          }

          [/CODE]
          </script>
          Last edited by acoder; Sep 18 '08, 11:48 AM. Reason: Added [code] tags

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #20
            Originally posted by risk32
            So... I should set the option value to equal selDay, SelMonth, and selYear
            and linkRef.href = selDay + selMonth + selYear?
            Yes, e.g. selDay would be set to document.getEle mentById("selDa y").value. However, you still need to set linkRef to the link element. Give the link an ID and access it using document.getEle mentById().

            Comment

            • risk32
              New Member
              • Mar 2008
              • 98

              #21
              Rsmastermind,
              Using your guidance, here's the coding I came up with.. not much different from where I started and I need a little more help on the JS portion of it.
              You may use any value for the linknode or nodeValue, just need to see an example of how I would do it.

              Code:
              <html>
              <select onchange="changeValue(this);">
              <option value="selDay">01</option>
              <option value="selDay">02</option>
              <option value="selDay">03</option>
              <option value="selDay">04</option>
              <option value="selDay">05</option>
              <option value="selDay">06</option>
              <option value="selDay">07</option>
              <option value="selDay">08</option>
              <option value="selDay">09</option>
              <option value="selDay">10</option>
              <option value="selDay">11</option>
              <option value="selDay">12</option>
              <option value="selDay">13</option>
              <option value="selDay">14</option>
              <option value="selDay">15</option>
              <option value="selDay">16</option>
              <option value="selDay">17</option>
              <option value="selDay">18</option>
              <option value="selDay">19</option>
              <option value="selDay">20</option>
              <option value="selDay">21</option>
              <option value="selDay">22</option>
              <option value="selDay">23</option>
              <option value="selDay">24</option>
              <option value="selDay">25</option>
              <option value="selDay">26</option>
              <option value="selDay">27</option>
              <option value="selDay">28</option>
              <option value="selDay">29</option>
              <option value="selDay">30</option>
              <option value="selDay">31</option>
              </select>
              
              <select onchange="changeValue(this);">
              <option value="selMonth">January</option>
              <option value="selMonth">February</option>
              <option value="selMonth">March</option>
              <option value="selMonth">April</option>
              <option value="selMonth">May</option>
              <option value="selMonth">June</option>
              <option value="selMonth">July</option>
              <option value="selMonth">August</option>
              <option value="selMonth">September</option>
              <option value="selMonth">October</option>
              <option value="selMonth">November</option>
              <option value="selMonth">December</option>
              </select>
              
              <select onchange="changeValue(this);">
              <option value="selYear">2008</option>
              </select>
              <script type="text/javascript">
              function changeValue(that){
              var linknode=$();
              var comboValue=.that.value;
              linknode.firstChild.nodeValue = ""
              }
              </script>
              <a href="javascript:myFunction();">Here is the slide</a>
              </html>

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #22
                For linknode or linkRef or whatever you want to call it, you need to access the link element, so give the <a> element an id and then use document.getEle mentById("id") to refer to it.

                Comment

                • Rsmastermind
                  New Member
                  • Sep 2008
                  • 93

                  #23
                  Originally posted by risk32
                  Rsmastermind,
                  Using your guidance, here's the coding I came up with.. not much different from where I started and I need a little more help on the JS portion of it.
                  You may use any value for the linknode or nodeValue, just need to see an example of how I would do it.

                  Code:
                  <html>
                  <select onchange="changeValue(this);">
                  <option value="selDay">01</option>
                  <option value="selDay">02</option>
                  <option value="selDay">03</option>
                  <option value="selDay">04</option>
                  <option value="selDay">05</option>
                  <option value="selDay">06</option>
                  <option value="selDay">07</option>
                  <option value="selDay">08</option>
                  <option value="selDay">09</option>
                  <option value="selDay">10</option>
                  <option value="selDay">11</option>
                  <option value="selDay">12</option>
                  <option value="selDay">13</option>
                  <option value="selDay">14</option>
                  <option value="selDay">15</option>
                  <option value="selDay">16</option>
                  <option value="selDay">17</option>
                  <option value="selDay">18</option>
                  <option value="selDay">19</option>
                  <option value="selDay">20</option>
                  <option value="selDay">21</option>
                  <option value="selDay">22</option>
                  <option value="selDay">23</option>
                  <option value="selDay">24</option>
                  <option value="selDay">25</option>
                  <option value="selDay">26</option>
                  <option value="selDay">27</option>
                  <option value="selDay">28</option>
                  <option value="selDay">29</option>
                  <option value="selDay">30</option>
                  <option value="selDay">31</option>
                  </select>
                  
                  <select onchange="changeValue(this);">
                  <option value="selMonth">January</option>
                  <option value="selMonth">February</option>
                  <option value="selMonth">March</option>
                  <option value="selMonth">April</option>
                  <option value="selMonth">May</option>
                  <option value="selMonth">June</option>
                  <option value="selMonth">July</option>
                  <option value="selMonth">August</option>
                  <option value="selMonth">September</option>
                  <option value="selMonth">October</option>
                  <option value="selMonth">November</option>
                  <option value="selMonth">December</option>
                  </select>
                  
                  <select onchange="changeValue(this);">
                  <option value="selYear">2008</option>
                  </select>
                  <script type="text/javascript">
                  function changeValue(that){
                  var linknode=$();
                  var comboValue=.that.value;
                  linknode.firstChild.nodeValue = ""
                  }
                  </script>
                  <a href="javascript:myFunction();">Here is the slide</a>
                  </html>


                  Yes but linknode you had specified as null.That is not correct
                  give like this in your document.[HTML]<a id="Link_ID">li nk value </a> //Assign this Id Link_ID to var linknode of your code[/HTML]

                  this will work fine.

                  Comment

                  • risk32
                    New Member
                    • Mar 2008
                    • 98

                    #24
                    Here's another way I tried to go about it... It works, but I need to find a way to adjust the filePath depending on the Airifield / Daily Schedule radio button. The filePath for Daily schedule is good, but I need a separate filePath for the Aifield so it reads var filePath = "INFO & STATUS\\Info & Status" with the same file extension as ".ppt".

                    The code:
                    Code:
                    <html>
                    <head>
                    <script>
                    
                    var year ="2008";
                    var fileExt = ".ppt";
                    
                    function getRadioButtonvalue(radioButtons)
                    {
                    	var value = null;
                    	for (var i=0; i<= radioButtons.length -1; i++)
                    	{
                    		if (radioButtons[i].checked)
                    		{
                    			value =radioButtons[i].value;
                    		}
                    	}
                    	return value;
                    }
                    
                    
                    function displayFileName()
                    {
                    	var day = getRadioButtonvalue(document.getElementsByName("day"));
                    	var month = getRadioButtonvalue(document.getElementsByName("month"));
                    	var filePath = getRadioButtonvalue(document.getElementsByName("month"));
                    	var fileName = filePath + "/" + day + " " + month + " " + year + fileExt;
                    	 
                    	//write to page..
                    	var downloadArea = document.getElementById("downloadArea");
                    	downloadArea.innerHTML = '<a href="'+fileName+'"> Click to download File </a>'; 
                    	 
                    }
                    </script>
                    
                    </HEAD>
                    <BODY>
                    
                    <TABLE cellSpacing="0" cellPadding="0" width="1111" bgColor="#999999" border="2">
                    
                    
                    <h5>Please Select Airfield Status Or Daily Schedule</h5>
                    <input type="radio" name="type" value="airfield">Airfield Status<br>
                    <input type="radio" name="type" value="schedule">Daily Schedule
                         
                    <h5>Please Select the Day<br></h5>
                    <input type="radio" name="day" value="01">01
                    <input type="radio" name="day" value="02">02
                    <input type="radio" name="day" value="03">03
                    <input type="radio" name="day" value="04">04
                    <input type="radio" name="day" value="05">05
                    <input type="radio" name="day" value="06">06
                    <input type="radio" name="day" value="07">07
                    <input type="radio" name="day" value="08">08
                    <input type="radio" name="day" value="09">09
                    <input type="radio" name="day" value="10">10
                    <input type="radio" name="day" value="11">11
                    <input type="radio" name="day" value="12">12
                    <input type="radio" name="day" value="13">13
                    <input type="radio" name="day" value="14">14
                    <input type="radio" name="day" value="15">15<br>
                    <input type="radio" name="day" value="16">16
                    <input type="radio" name="day" value="17">17
                    <input type="radio" name="day" value="18">18
                    <input type="radio" name="day" value="19">19
                    <input type="radio" name="day" value="20">20
                    <input type="radio" name="day" value="21">21
                    <input type="radio" name="day" value="22">22
                    <input type="radio" name="day" value="23">23
                    <input type="radio" name="day" value="24">24
                    <input type="radio" name="day" value="25">25
                    <input type="radio" name="day" value="26">26
                    <input type="radio" name="day" value="27">27
                    <input type="radio" name="day" value="28">28
                    <input type="radio" name="day" value="29">29
                    <input type="radio" name="day" value="30">30
                    <input type="radio" name="day" value="31">31
                    
                    <h5>Please Select the month</h5>
                    <input type="radio" name="month" id="Janauary" value="jan">January<br>
                    <input type="radio" name="month" id="February" value="feb">February<br>
                    <input type="radio" name="month" id="March" value="mar">March<br>
                    <input type="radio" name="month" id="April" value="apr">April<br>
                    <input type="radio" name="month" id="May" value="may">May<br>
                    <input type="radio" name="month" id="June" value="jun">June<br>
                    <input type="radio" name="month" id="July" value="jul">July<br>
                    <input type="radio" name="month" id="August" value="aug">August<br>
                    <input type="radio" name="month" id="September" value="sep">September<br>
                    <input type="radio" name="month" id="October" value="oct">October<br>
                    <input type="radio" name="month" id="November" value="nov">November<br>
                    <input type="radio" name="month" id="December" value="dec">December<br>
                    <br>
                    
                    <H3>Please Select the Appropiate Link</H3>
                    
                    <input type="button" value="Generate Link" onClick="displayFileName()">
                    <input type="reset" value="reset">
                    <div id="downloadArea"></div>
                    </body>
                    </html>

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #25
                      Use the getRadioButtonV alue function to get the value of the "type" radio button. If it's Aifield, you can set it to "INFO AND STATUS..". I think select elements would be more useful than radio buttons for the day/month and make the code shorter too.

                      Comment

                      • risk32
                        New Member
                        • Mar 2008
                        • 98

                        #26
                        Originally posted by acoder
                        Use the getRadioButtonV alue function to get the value of the "type" radio button. If it's Aifield, you can set it to "INFO AND STATUS..". I think select elements would be more useful than radio buttons for the day/month and make the code shorter too.
                        Acoder,
                        Using your advice I changed the radio value for airfield to "INFO & STATUS\Info and Status.ppt" and it worked! Success! Almost... In order to do that I had to change var fileName to just filePath.. now I'm stuck with trying to figure out how to toggle between two filepaths... (by the way, never took and JDK or JS classes, just learning as I go by using forums, online books etc... big pain in the a$$ if you ask me.. should have taken a class)

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #27
                          What I was suggesting was along the lines of:
                          Code:
                          var type = getRadioButtonvalue(document.getElementsByName("type"));
                          // now check type value
                          if (type == "airfield") {
                           // set fileName to "INFO...", etc.
                          } else {
                              // get day/month values and set fileName
                          }

                          Comment

                          • risk32
                            New Member
                            • Mar 2008
                            • 98

                            #28
                            This If / Else statement is throwing errors. This is the only part I changed
                            Code:
                            function displayFileName()
                            {
                            var type = getRadioButtonValue(document.getElementsByName("schedule")); 
                             if (type == "schedule") {
                                var day = getRadioButtonvalue(document.getElementsByName("day")); 
                                var month = getRadioButtonvalue(document.getElementsByName("month"));
                                var filePath = "M:\\data\\Duty Desk\\Electronic Boards Info\\Schedule Slides\\2008\\"
                                var fileName = filePath +  month + "\\" + day + " " + month + " " + year + fileExt;
                             } else {
                            var filePath = "M:\\data\\Duty Desk\\Electronic Boards Info\\Schedule Slides\\2008\\INFO & STATUS\\"
                            var fileName = filePath + "Info And Status" + fileExt;
                            Last edited by risk32; Sep 28 '08, 07:21 AM. Reason: Code Typographics

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #29
                              What error messages do you see?

                              Don't forget to close the else part with a closing bracket.

                              Comment

                              • risk32
                                New Member
                                • Mar 2008
                                • 98

                                #30
                                Line 35, Char 1
                                Expected character '}'
                                Doesn't really make sense since it's html and not javascript on Ln 35

                                Line 89 Char 1
                                Object Expected
                                Code:
                                <html>
                                <head>
                                <script>
                                var year ="2008";
                                var fileExt = ".ppt";
                                function getRadioButtonvalue(radioButtons)
                                {
                                var value = null;
                                for (var i=0; i<= radioButtons.length -1; i++)
                                {
                                if (radioButtons[i].checked)
                                {
                                value =radioButtons[i].value;
                                }
                                }
                                return value;
                                }
                                function displayFileName()
                                 { 
                                var type = getRadioButtonValue(document.getElementsByName("schedule"));  
                                 if (type == "schedule") { 
                                    var day = getRadioButtonvalue(document.getElementsByName("day"));  
                                    var month = getRadioButtonvalue(document.getElementsByName("month")); 
                                    var filePath = "M:\\data\\Duty Desk\\Electronic Boards Info\\Schedule Slides\\2008\\" 
                                    var fileName = filePath +  month + "\\" + day + " " + month + " " + year + fileExt; 
                                } else {
                                var filePath = "M:\\data\\Duty Desk\\Electronic Boards Info\\Schedule Slides\\2008\\INFO & STATUS\\" 
                                var fileName = filePath + "Info And Status" + fileExt; 
                                var downloadArea = document.getElementById("downloadArea"); 
                                    downloadArea.innerHTML = '<a href="'+fileName+'"> Click to download File </a>';
                                </script>
                                </HEAD>
                                <BODY>
                                <TABLE cellSpacing="0" cellPadding="0" width="1111" bgColor="#999999" border="2">
                                <h5>Please Select Airfield Status Or Daily Schedule</h5>
                                <input type="radio" name="type" value="INFO & STATUS\Info and Status.ppt">Airfield Status<br>
                                <input type="radio" name="type" value="">Daily Schedule
                                <h5>Please Select the Day<br></h5>
                                <input type="radio" name="day" value="01">01
                                <input type="radio" name="day" value="02">02
                                <input type="radio" name="day" value="03">03
                                <input type="radio" name="day" value="04">04
                                <input type="radio" name="day" value="05">05
                                <input type="radio" name="day" value="06">06
                                <input type="radio" name="day" value="07">07
                                <input type="radio" name="day" value="08">08
                                <input type="radio" name="day" value="09">09
                                <input type="radio" name="day" value="10">10
                                <input type="radio" name="day" value="11">11
                                <input type="radio" name="day" value="12">12
                                <input type="radio" name="day" value="13">13
                                <input type="radio" name="day" value="14">14
                                <input type="radio" name="day" value="15">15<br>
                                <input type="radio" name="day" value="16">16
                                <input type="radio" name="day" value="17">17
                                <input type="radio" name="day" value="18">18
                                <input type="radio" name="day" value="19">19
                                <input type="radio" name="day" value="20">20
                                <input type="radio" name="day" value="21">21
                                <input type="radio" name="day" value="22">22
                                <input type="radio" name="day" value="23">23
                                <input type="radio" name="day" value="24">24
                                <input type="radio" name="day" value="25">25
                                <input type="radio" name="day" value="26">26
                                <input type="radio" name="day" value="27">27
                                <input type="radio" name="day" value="28">28
                                <input type="radio" name="day" value="29">29
                                <input type="radio" name="day" value="30">30
                                <input type="radio" name="day" value="31">31
                                <h5>Please Select the month</h5>
                                <input type="radio" name="month" id="Janauary" value="jan">January<br>
                                <input type="radio" name="month" id="February" value="feb">February<br>
                                <input type="radio" name="month" id="March" value="mar">March<br>
                                <input type="radio" name="month" id="April" value="apr">April<br>
                                <input type="radio" name="month" id="May" value="may">May<br>
                                <input type="radio" name="month" id="June" value="jun">June<br>
                                <input type="radio" name="month" id="July" value="jul">July<br>
                                <input type="radio" name="month" id="August" value="aug">August<br>
                                <input type="radio" name="month" id="September" value="sep">September<br>
                                <input type="radio" name="month" id="October" value="oct">October<br>
                                <input type="radio" name="month" id="November" value="nov">November<br>
                                <input type="radio" name="month" id="December" value="dec">December<br>
                                <br>
                                <H3>Please Select the Appropiate Link</H3>
                                <input type="button" value="Generate Link" onClick="displayFileName()">
                                <input type="reset" value="reset">
                                <div id="downloadArea"></div>
                                </body>
                                </html>
                                Last edited by risk32; Sep 29 '08, 05:03 AM. Reason: Addition

                                Comment

                                Working...