Current location: Hot Scripts Forums » General Web Coding » JavaScript » fetch id with javascript

fetch id with javascript

Reply
  #1 (permalink)  
Old 06-22-09, 06:22 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
fetch id with javascript

hi all

like there is a url
Code:
manage_products.php?page=2
If i want to fetch page id in php then i will write
Code:
$page=$_REQUEST['page'];
Now if i want to fetch page id in Javascript then what should be my code in javascript.

vineet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-22-09, 07:33 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,572
Thanks: 5
Thanked 27 Times in 24 Posts
Code:
var url = window.href.toString();
var id  = url.match(/\?page=(\d+)/);

if (id[1])
{
    alert('The ID is: ' + id[1]);
}
else
{
    alert('No ID found');
}
... untested, but should work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-22-09, 07:48 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,726
Thanks: 0
Thanked 32 Times in 32 Posts
Quote:
Originally Posted by Nico View Post
Code:
var url = window.href.toString();
Should be:
HTML Code:
var url = window.location.href.toString();

or

var url = location.href.toString();

or

var url = window.location.href;

or

var url = location.href;
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-22-09, 08:27 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
fetch id

hi nico

thanks. it works fine but as sugested by job0107 with window.location.href.toString();

now if i need to fetch value that is not numeric,
like if i have url like
Code:
manage_products.php?choice=free
if i need to fetch value of choice that is "free" and its not numeric, then will this same function work or i need a different function for that.


vineet

Quote:
Originally Posted by Nico View Post
Code:
var url = window.href.toString();
var id  = url.match(/\?page=(\d+)/);

if (id[1])
{
    alert('The ID is: ' + id[1]);
}
else
{
    alert('No ID found');
}
... untested, but should work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-22-09, 08:39 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,572
Thanks: 5
Thanked 27 Times in 24 Posts
Replace \d with \w. The rest stays the same.


And thanks, Jerry!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-22-09, 08:56 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
fetch id

Quote:
Originally Posted by Nico View Post
Replace \d with \w. The rest stays the same.


And thanks, Jerry!
hi nico

what does \d and \w stands for

vineet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-22-09, 09:00 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,572
Thanks: 5
Thanked 27 Times in 24 Posts
\d matches numbers (digits)
\w matches word characters. [A-Z a-z _]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 06-22-09, 09:02 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,726
Thanks: 0
Thanked 32 Times in 32 Posts
..........
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 06-22-09, 09:09 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
hi

thanks to both nico and jerry for helping me and clarifying my doubts.

vineet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add javascript after load? <?Wille?> JavaScript 14 03-31-06 04:52 AM
Mixing some HTML into some JavaScript thatonedude JavaScript 2 12-30-05 11:04 AM
javascript /forms /checkboxes /arrays ski_woman JavaScript 1 11-16-04 04:08 AM
Reaaly stuck about javascript over frames muratisik JavaScript 1 12-14-03 11:58 AM


All times are GMT -5. The time now is 10:47 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.