Yes this is an error u need to close all the braces If the brace will be opened the javascript will not get executed.
Javascript Replace()
Collapse
X
-
-
OK, looked at the IE error report is put out, though the line numbers arent the exact number is says. I'm pretty sure it's throwing an error due to the "downloadAr ea" portion of it. I've gotten it to work before, but after that, I had to throw in the IF/ELSE statement... might just be syntax and/or placement issues.
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")); var downloadArea = document.getElementById("downloadArea"); downloadArea.innerHTML = '<a href="'+fileName+'"> Click to download File </a>'; 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; </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" onclick="window.location.reload(true); return false;"> <div id="downloadArea"></div> </body> </html>
Comment
-
Change it back to what you had before. The download Area lines have to appear after the if/else statement because that's where the fileName variable is set.
What you needed to do was add two brackets. One to close the else and one to close the function. Whenever you have an opening { you need a matching close }.
One final thing: don't trust IE error message line numbers. They're very often horribly wrong. First test in a decent other browser such as Firefox or Opera, then finally test in IE.Comment
-
Originally posted by acoderChange it back to what you had before. The download Area lines have to appear after the if/else statement because that's where the fileName variable is set.
What you needed to do was add two brackets. One to close the else and one to close the function. Whenever you have an opening { you need a matching close }.
One final thing: don't trust IE error message line numbers. They're very often horribly wrong. First test in a decent other browser such as Firefox or Opera, then finally test in IE.
Code: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")); var day = getRadioButtonvalue(document.getElementsByName("day")); var month = getRadioButtonvalue(document.getElementsByName("month")); var downloadArea = document.getElementById("downloadArea"); } if (type == "schedule") { var filePath = getRadioButtonvalue(document.getElementsByName("month")); var fileName = filePath + "/" + 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; } { //write to page.. downloadArea.innerHTML = '<a href="'+fileName+'"> Click to download File </a>'; } </script> <html> ...... <div id"downloadArea"> </html>
Comment
-
There are a number of syntax errors.
On line 21, you close the function displayFileName which is not what you want, so remove that line. Lines 27/28 need to be swapped round because the if-else syntax is "if { ... } else { ... }", not "if { ... } { else }". Finally, on line 32, you're opening a block of code with { which is not required, so remove that line too.Comment
-
Originally posted by acoderThere are a number of syntax errors.
On line 21, you close the function displayFileName which is not what you want, so remove that line. Lines 27/28 need to be swapped round because the if-else syntax is "if { ... } else { ... }", not "if { ... } { else }". Finally, on line 32, you're opening a block of code with { which is not required, so remove that line too.
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")); var day = getRadioButtonvalue(document.getElementsByName("day")); var month = getRadioButtonvalue(document.getElementsByName("month")); var downloadArea = document.getElementById("downloadArea"); if (type == "schedule") { var filePath = getRadioButtonvalue(document.getElementsByName("month")); var fileName = filePath + "/" + 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; } //write to page.. 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" onclick="window.location.reload(true); return false;"> <div id="downloadArea"></div> </body> </html>
Thanks for the help acoderComment
-
I notice a few more errors. You haven't closed displayFileName properly. There should be a closing } after the last line of the function before </script>.
The type value is incorrect because you're getting the radio button value of elements named "schedule" instead of "type". Secondly, you will get an error because JavaScript is case-sensitive and you calling the getRadioButtonv alue() function with a capital V instead of a lower-case v.
See if that helps fix things.Comment
-
Originally posted by acoderI notice a few more errors. You haven't closed displayFileName properly. There should be a closing } after the last line of the function before </script>.
The type value is incorrect because you're getting the radio button value of elements named "schedule" instead of "type". Secondly, you will get an error because JavaScript is case-sensitive and you calling the getRadioButtonv alue() function with a capital V instead of a lower-case v.
See if that helps fix things.
Now all I've got to do is make sure every single .ppt file is in the correct format to open it according to the link. I've got all kinds of different ways people have saved these slides... Ugh... :( But that comes with the terriroty of being a Computer Support Assistant AND being a Duty Officer for a C-130 squadron.
Is there a way to add a login form and change visible to false until the correct login is input? Also, without a server-side ability, is there a way to add cookies using a mapped network drive and fake a folder to act as a server? Reason I'm asking... we have a network server, with no direct access to the configuration or software on it iself. Most file extensions are blocked except those savable under Microsoft office, html, and .js files. ALL .exes are blocked as well as .bats
Is there a way to write it in javascript to fake itself to create an object to act as a server for the cookies function? We've got 180 people and some higher ups that need access to this webpage for historical purposes and having MySQL is just not an option for maintaining usernames and password for it. It's not classified information, but still need to prevent anyone not part of our office looking at it.
I greatly appreciate your help. Without it I'd be pulling my hair out of just giving up on this html. With the guidance you've given, I understand JS a little more and realize how strict the language is, unlike VB or html. Again, thank you.Comment
-
I'm afraid that won't be possible. You can use cookies without a server, but for any type of login security, you will need server-side code. JavaScript doesn't offer much protection. Any that it does is easily circumvented by anyone with even a bit of knowledge.
What type of server/network is it? There may be options that you could consider, but they wouldn't involve JavaScript, so you can try asking in an appropriate forum, or Misc. Questions if nothing fits.
Personally, I would consider a proper server setup which allows you to control access.
Anyway, glad to hear that you've got the original problem solved. You could improve it further by using select elements instead of radio buttons.Comment
-
Originally posted by acoderI'm afraid that won't be possible. You can use cookies without a server, but for any type of login security, you will need server-side code. JavaScript doesn't offer much protection. Any that it does is easily circumvented by anyone with even a bit of knowledge.
What type of server/network is it? There may be options that you could consider, but they wouldn't involve JavaScript, so you can try asking in an appropriate forum, or Misc. Questions if nothing fits.
Personally, I would consider a proper server setup which allows you to control access.
Anyway, glad to hear that you've got the original problem solved. You could improve it further by using select elements instead of radio buttons.
Anyways, I tried using the select elements for a drop down menu with JS but it was to no avail. I couldn't get the element values to cross over into each menu and there would be 365+ option values.... WAY too much coding when I could use radio buttons like this. Unless of course, all I have to do in this code is substitute the radio button for a select. Also, the site is working just fine, just need to keep maintenance contantly since most people don't know how to save the .ppt files the right way... Also implemented an Excel VBA project that does the same thing, just trying to transfer it over to VB6 for compiling. Hopefully this gets some good feedback for the work I've been doing to improve operations.Comment
-
To use select elements, replace the radio buttons with select/option elements in the HTML, e.g. for day:
Code:<select id="day"> <option value="01">01
Code:var day = document.getElementById("day").value;
Comment
-
Originally posted by acoderTo use select elements, replace the radio buttons with select/option elements in the HTML, e.g. for day:
Code:<select id="day"> <option value="01">01
Code:var day = document.getElementById("day").value;
Anyways, I separated the code into a .js and .html, mostly so I dont have to keep looking at the same code over and over. I can fix one or both and not have to worry so much.
Here's the .js, called link.js (nothing really changed since the last time I posted it)
Code: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")); var day = document.getElementsById("day"); var month = document.getElementById("month"); var downloadArea = document.getElementById("downloadArea"); if (type == "schedule") { var filePath = "\\Duty Desk\\Electronic Boards Info\\Schedule Slides\\2008" var fileName = filePath + "/" + month + "/" + day + " " + month + " " + year + fileExt; } else { var filePath = "Duty Desk\\Electronic Boards Info\\Schedule Slides\\2008\\INFO & STATUS\\" var fileName = filePath + "Info And Status" + fileExt; } //write to page.. downloadArea.innerHTML = '<a href="'+fileName+'"> Click to download File </a>'; }
Code:<html> <BODY> <script type="text/javascript" src="link.js"> </script> <TABLE cellSpacing="0" cellPadding="0" width="1111" bgColor="#999999" border="2"> <h5>Please Select Airfield Status Or Daily Schedule</h5> <input type="radio" name="airfield" value="airfield">Airfield Status<br> <input type="radio" name="schedule" value="schedule">Daily Schedule <h5>Please Select the Day<br></h5> <select id="day"> <option value="01">01 <option value="02">02 <option value="03">03 <option value="04">04 <option value="05">05 <option value="06">06 <option value="07">07 <option value="08">08 <option value="09">09 <option value="10">10 <option value="11">11 <option value="12">12 <option value="13">13 <option value="14">14 <option value="15">15 <option value="16">16 <option value="17">17 <option value="18">18 <option value="19">19 <option value="20">20 <option value="21">21 <option value="22">22 <option value="23">23 <option value="24">24 <option value="25">25 <option value="26">26 <option value="27">27 <option value="28">28 <option value="29">29 <option value="30">30 <option value="31">31 </select> <h5>Please Select the month</h5> <select id="month"> <option value="january">January <option value="february">February <option value="march">March <option value="april">April <option value="may">May <option value="june">June <option value="july">July <option value="august">August <option value="september">September <option value="october">October <option value="november">November <option value="decemeber">December </select> <br> <H3>Please Select the Appropiate Link</H3> <input type="button" value="Generate Link" onClick="displayFileName()"> <input type="reset" value="reset" onclick="window.location.reload(true); return false;"> <div id="downloadArea"></div> </body> </html>
Thanks again,
AdamComment
Comment