The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 11:36:38 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Parsing a URL for the existance of Query Paramaters  (Read 2100 times)
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« on: November 24, 2009, 02:01:40 PM »

Hey folks,

I've recently come across a problem I need to solve with JS but being a JS newbie I'm having a few problems - I'm hoping someone here may have done something similar in the past, or may be able to help.

Basically I want to check a URL for the existance of query paramaters, if they exist append using &param=1 else ?param=1. Only I'm useless with regex at the best of times, let alone in JavaScript - any ideas?

Cheers,

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: November 24, 2009, 02:24:41 PM »


if (inputURL.match(/\?/))
   alert('There is a query string on the inputURL variable.');


.match is a simple way of checking the input string (an object) against a regex. Note that the regex is NOT enclosed in quotes.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #2 on: November 24, 2009, 04:26:25 PM »

Thanks Perk.

Forgive my ignorance but how would I make the input url an object? I tried just assigning a string to a variable but that didn't seem to work.

DM
Logged
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #3 on: November 24, 2009, 04:29:46 PM »

Scratch that - school boy syntax error. All sorted.

Thanks again Perk.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: November 24, 2009, 04:31:17 PM »

no worries mate Smiley
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!