SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question location.search problem

    Hi all, I have a small problem with some javascript validation that I am doing, I want to use the same javascript for validating a registration form, and then when you edit your account details to use the same validation form, except there are some fields that are not editable and dont appear. I though of this method.

    var qString = location.search;
    var process = qString.substring(qString.indexOf("action=") + 7, qString.length);

    if (process == "edit")
    validate edit form
    }
    else {
    validate add form
    }

    now with this, is what I used on a previous validation, and the url looked something liek this:
    http://www.site.com/?pace=account&action=edit

    that works fine for me, now my problem is that I am using PHP sessions and mod_rewrite and storing data in those, so this time my URL looks something like:

    http://www.site.com/edit

    now the javascript doesnt work for that page, any suggestions?

    Thanks in advance.
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    location.search only has contains the query string including the '?'.

    You need to use location.href or location.pathname now.

    Code:
    var process = location.pathname;
    
    if (process.indexOf("edit") != -1)
    validate edit form
    }
    else {
    validate add form
    }
    Is there any chance that you could show me the mod_rewrite section of your .htaccess file? I've been trying to get it to work on the servers I use, but have been unable to, and the documentation and other articles online have not helped.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fantastic, thanks for the help, that seems to work perfectly for me

    Tell me what does the != -1 mean?

    I have sent you a pvt message with the mod_rewrite
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome and thanks for the pvt message.

    indexOf() returns -1 when the string is not found, so I was testing to make sure that the string is found.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

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