www.webdeveloper.com
Results 1 to 14 of 14

Thread: Simple Syntax Error but I can't Figure it out ...

  1. #1
    Join Date
    Sep 2010
    Posts
    11

    Simple Syntax Error but I can't Figure it out ...

    Hello,

    In the functions that I created below, I constantly gt errors on the variables created on the first lines. Anyone know what that may be?

    Thanks:

    Code:
    <script language="JavaScript"> 
    /* Which browser? */
    var IE4 = (document.all);
    var NS4 = (document.layers);
    /* window to search. */
    var win = window;
    var n = 0;
    function findInPageStudents(str) {
    var txt = '';
    var i = 0;
    var found = '';
    if (str == "") return false;
    /* Find next occurance of the given string on the page, wrap around to the start of the page if necessary. */
    if (NS4) {
    /* Look for match starting at the current point.
    If not found, rewind back to the first match. */
    if (!win.find(str)) while(win.find(str, false, true)) n++; else n++;
    /* If not found in either direction, give message. */
    if (n == 0) alert("Not found.");
    }
    if (IE4) {
    txt = win.document.body.createTextRange();
    /* Find the nth match from the top of the page. */
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); }
    /* If found, mark it and scroll it into view. */
    if (!(found = '')) {
    var strStudentMenu = '';
    strStudentMenu = 'http://wesleyweb.wesleyseminary.edu/';
    strStudentMenu = strStudentMenu + 'WAPROD/WAPROD?type=M&constituency'; strStudentMenu = strStudentMenu + '=WBST&pid=CORE-WBST'; window.location = strStudentMenu;
    }
    /* Otherwise, start over at the top of the page and find first match. */
    else {
    if (n > 0) {
    n = 0;
    findInPageStudents(str);
    }
    /* Not found anywhere, give message.*/
    else alert("Not found.");
    }
    }
    return false;
    }
    
    function findInPageFaculty(str) {
    var txt = '';
    var i = 0;
    var found = '';
    if (str == "") return false;
    /* Find next occurance of the given string on the page, wrap around to the
       start of the page if necessary. */
    if (NS4) {
    /* Look for match starting at the current point.
      If not found, rewind back to the first match. */
    if (!win.find(str)) while(win.find(str, false, true)) n++; else n++;
    /* If not found in either direction, give message. */
    if (n == 0) alert("Not found.");
    }
    if (IE4) {
    txt = win.document.body.createTextRange();
    /* Find the nth match from the top of the page. */
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); }
    /* If found, mark it and scroll it into view. */
    if (!(found = '')) {
    var strStudentMenu;
    strStudentMenu = 'http://wesleyweb.wesleyseminary.edu/';
    strStudentMenu = strStudentMenu + 'WAPROD/WAPROD?type=M&constituency'; strStudentMenu = strStudentMenu + '=WBFC&pid=CORE-WBFC'; window.location = strStudentMenu;
    }
    /* Otherwise, start over at the top of the page and find first match. */
    else {
    if (n > 0) {
    n = 0;
    findInPageFaculty(str);
    }
    /* Not found anywhere, give message.*/
    else alert("Not found.");
    }
    }
    return false;
    }
    findInPageStudents('[[[Students]]]');
    findInPageFaculty('[[[Faculty]]]');
    </script>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Well, I doubt you have created that code, as it appears to have being dug from the bottom of the of the bottom of the Jurassic patterns of the JavaScript (the '90s). These days there are no: 'language="JavaScript", nor NS4, nor IE4... It is a medieval code which I doubt will fit in any modern browser. My God, where did you find it?

    In fact, what the code should do?
    Last edited by Kor; 09-24-2010 at 12:30 PM.

  3. #3
    Join Date
    Sep 2010
    Posts
    11

    Question

    Quote Originally Posted by Kor View Post
    Well, I doubt you have created that code, as it appears to have being dug from the bottom of the of the bottom of the Jurassic patterns of the JavaScript (the '90s). These days there are no: 'language="JavaScript", nor NS4, nor IE4... It is a medieval code which I doubt will fit in any modern browser. My God, where did you find it?

    In fact, what the code should do?
    Basically, what I need the code to do is find some text on the webpage and then, based on the text, redirect the user to a certain site.

    Does that make sense?

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by ckoeber View Post
    find some text on the webpage and then, based on the text, redirect the user to a certain site.
    Find where? The document might have text within its content, inside form's elements (as string value), and so on...

    What text to find? Compare with what? Where?

    Redirect when? What should the user do to redirect the page?

    Can you detail your aim, please?

    ---
    Do you know HTML, CSS, JavaScript?

  5. #5
    Join Date
    Sep 2010
    Posts
    11

    Question

    Quote Originally Posted by Kor View Post
    Find where? The document might have text within its content, inside form's elements (as string value), and so on...
    Within the content of the web document. Not in the elements, etc. but what is visible.

    Quote Originally Posted by Kor View Post
    What text to find? Compare with what? Where?
    A custom string that, based on how the user logs in to the page, the text changes. So, as it stands now I have text that changes on the page to "[[[Students]]]" when a student logs in and "[[[Faculty]]]" when a faculty member logs in.

    If everything works correctly the people who log in will barely notice this.

    Quote Originally Posted by Kor View Post
    Redirect when? What should the user do to redirect the page?
    Nothing. The user should log in, the text should appear from the application I am using, and based on the text of the page that appears they should be redirected to the page as defined in the javascript code.

    Makes sense?

    Quote Originally Posted by Kor View Post
    Can you detail your aim, please?
    Done.

    Quote Originally Posted by Kor View Post
    Do you know HTML, CSS, JavaScript?
    Yes, I do, but I am not an expert.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    A custom string that, based on how the user logs in to the page
    That sounds like a user/password access. Usually this is to be done on using a server-side code and a Data Base. Do I miss something?

  7. #7
    Join Date
    Sep 2010
    Posts
    11
    Quote Originally Posted by Kor View Post
    That sounds like a user/password access. Usually this is to be done on using a server-side code and a Data Base. Do I miss something?
    Normally you would be correct but this is a legacy application and I don't have that ability.

    I can, however, change client side code and hence this request.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    OK. Forget about your code. Put your problem in another way: I need to do that and that, when a user does that and that. Detail. Use common words, if you are not a coder. Be a little more descriptive, please.

  9. #9
    Join Date
    Sep 2010
    Posts
    11

    Question

    Quote Originally Posted by Kor View Post
    OK. Forget about your code. Put your problem in another way: I need to do that and that, when a user does that and that. Detail. Use common words, if you are not a coder. Be a little more descriptive, please.
    OK, here you go:

    We have a online Student system that students access via the web. The student can search for courses, log into their accounts, and view status messages.

    When they log in successfully, they are presented with the same EXACT menu as prescribed before BUT with a link to their prospective section (one set of students get one link, another set of students gets another link).

    So, our legacy system does not have the ability to redirect people. Therefore, I would like to create a JavaScript function that redirects people to the appropriate place they need to go based on the link that is sent from the legacy application. I can change the text of the link, so the JavaScript application can find that text.

    Any other clarification needed?

    Thank you for your time.

  10. #10
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    So, there is a certain link somewhere with a certain href value. Do you want to redirect the page onload to that url?

  11. #11
    Join Date
    Sep 2010
    Posts
    11

    Question

    Quote Originally Posted by Kor View Post
    So, there is a certain link somewhere with a certain href value. Do you want to redirect the page onload to that url?
    Yes, but after the person logs in as the href value that I want to redirect to only appears after the person is logged in.

  12. #12
    Join Date
    Sep 2010
    Posts
    11

    Question

    Is there anyone that can help me out with this?

    I am pretty sure that it is possible to code a javascript function to redirect a person to a different webpage based off of text on that webpage.

    Thanks for your help.

  13. #13
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    var contents=document.body.innerHTML;
    var idx=contents.search('[[[Students]]]');
    location.href = (idx!=-1)? 'student.htm' : 'faculty.htm';
    At least 98% of internet users' DNA is identical to that of chimpanzees

  14. #14
    Join Date
    Sep 2010
    Posts
    11

    Question

    Quote Originally Posted by Fang View Post
    Code:
    var contents=document.body.innerHTML;
    var idx=contents.search('[[[Students]]]');
    location.href = (idx!=-1)? 'student.htm' : 'faculty.htm';
    Thanks! This works.

    I changed the code a little to accommodate how the system works but the code works like a charm:

    Code:
    <script language="JavaScript"> 
    function findInPageStudents() {
    var strStudentMenu = '';
    strStudentMenu = 'http://wesleyweb.wesleyseminary.edu/';
    strStudentMenu = strStudentMenu + 'WAPROD/WAPROD?type=M&constituency'; strStudentMenu = strStudentMenu + '=WBST&pid=CORE-WBST';
    var strFacultyMenu;
    strFacultyMenu = 'http://wesleyweb.wesleyseminary.edu/';
    strFacultyMenu = strFacultyMenu + 'WAPROD/WAPROD?type=M&constituency'; strFacultyMenu = strFacultyMenu + '=WBFC&pid=CORE-WBFC';
    var contents=document.body.innerHTML;
    var idx=contents.search('[[[Students]]]');
    if (idx!=-1) {
    location.href = strStudentMenu;
    }
    else {
    idx=contents.search('[[[Faculty]]]');
    if (idx!=-1) {
    location.href = strFacultyMenu;
    }
    else {
    }
    }
    }
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles