473,799 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to extract from a URL and append to a link (javascript?)

2 New Member
Hi-
I would like to extract a value from the displayed url in the address, i.e. the 222 from
http://www.virtual.com/test.htm?sid=22 2

I now need to hold that value in a variable
var XXX= 222 for example
and dynamically append it to links on the page (sometimes all of the links, other times only some of the links)... this value XXX is different for every incoming link landing on this page.

The new link needs to be constructed as:
http://www.virtual.com/newpage.htm?sid = + XXX

so the new link works as if it were:
<a href=http://www.virtual.com/newpage.htm?sid =222>newlink</a>

What is the proper syntax please? I can only do this via html or javascript (no php).

Thanks in advance for the help-
Jim
Jan 19 '07 #1
5 8174
r035198x
13,262 MVP
Hi-
I would like to extract a value from the displayed url in the address, i.e. the 222 from
http://www.virtual.com/test.htm?sid=22 2

I now need to hold that value in a variable
var XXX= 222 for example
and dynamically append it to links on the page (sometimes all of the links, other times only some of the links)... this value XXX is different for every incoming link landing on this page.

The new link needs to be constructed as:
http://www.virtual.com/newpage.htm?sid = + XXX

so the new link works as if it were:
<a href=http://www.virtual.com/newpage.htm?sid =222>newlink</a>

What is the proper syntax please? I can only do this via html or javascript (no php).

Thanks in advance for the help-
Jim
Just have a look at string variables. There are a lot of methods available for use with strings
Jan 20 '07 #2
johnhjohn
43 New Member
To get the value after the ?sid and to assign it to a variable you could use the following:

var xxx = window.loaction .search.substr( 5);

This will make xxx equal to 222 (if I remember correctly). I am not sure what you are saying that you want to do from there, but I hoped I helped.
Jan 20 '07 #3
jimFDAC
2 New Member
To get the value after the ?sid and to assign it to a variable you could use the following:

var xxx = window.loaction .search.substr( 5);

This will make xxx equal to 222 (if I remember correctly). I am not sure what you are saying that you want to do from there, but I hoped I helped.
After I am able to assign the value 222 in variable XXX, I want to append it to existing links on that page so I guess the question becomes...

How do I append this variable value to the end of a url? This link
<a href="http://www.virtual.com/newpage.htm?sid =">pagelink</a> would need to have the 222 value of XXX added to the end of the url, so it reads
<a href="http://www.virtual.com/newpage.htm?sid =222">pagelink</a>

Can something be written to assign this?
Thx- Jim
Jan 20 '07 #4
r035198x
13,262 MVP
After I am able to assign the value 222 in variable XXX, I want to append it to existing links on that page so I guess the question becomes...

How do I append this variable value to the end of a url? This link
<a href="http://www.virtual.com/newpage.htm?sid =">pagelink</a> would need to have the 222 value of XXX added to the end of the url, so it reads
<a href="http://www.virtual.com/newpage.htm?sid =222">pagelink</a>

Can something be written to assign this?
Thx- Jim
You could submit through a form.

[HTML]<a href="" onClick = "javascript:doc ument.forms['formName'].submit()">[/HTML]



onSubmit of the form call a method which sets the action value of the form
i.e
[HTML]fromName.action = "http://www.virtual.com/newpage.htm?sid =" + XXX;[/HTML]
Jan 20 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
After I am able to assign the value 222 in variable XXX, I want to append it to existing links on that page so I guess the question becomes...

How do I append this variable value to the end of a url? This link
<a href="http://www.virtual.com/newpage.htm?sid =">pagelink</a> would need to have the 222 value of XXX added to the end of the url, so it reads
<a href="http://www.virtual.com/newpage.htm?sid =222">pagelink</a>

Can something be written to assign this?
Thx- Jim
To get the string that you require, use substr and indexOf:
Expand|Select|Wrap|Line Numbers
  1. var str = location.href.substr(location.href.indexOf("?sid=")+5);
The 5 will add onto the position of the ? giving you the number only.

To add to the end of a URL is easy. Use javascript to write to the screen:
Expand|Select|Wrap|Line Numbers
  1. document.write('<a href="http://www.virtual.com/newpage.htm?sid='+str+'">pagelink</a>');
The str string is added to the url after sid= (+ is the string concatenation operator).
Jan 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2234
by: SteveJ | last post by:
All, Can someone help me solve the next step. First of all let me say I'm new to php. I pieced the following code together from samples I found on the net and a book I bought called PHP Cookbook. So please forgive me if this isn't the best approach - I'm open to suggestions I finally got my code to work that logs into another site and pulls the orderstatus page to my server.
11
3176
by: Ren | last post by:
Suppose I have a file containing several lines similar to this: :10000000E7280530AC00A530AD00AD0B0528AC0BE2 The data I want to extract are 8 hexadecimal strings, the first of which is E728, like this: :10000000 E728 0530 AC00 A530 AD00 AD0B 0528 AC0B E2 Also, the bytes in the string are reversed. The E728 needs to be 28E7,
9
3503
by: chrisspencer02 | last post by:
I am looking for a method to extract the links embedded within the Javascript in a web page: an ActiveX component, or example code in C++/Pascal/etc. I am looking for a general solution, not one tailored to a particular page/script. Hopefully, the problem can be solved without recreating a complete Javascript interpreter. Any ideas?
7
2537
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair. This URL needs to open in a floating window if clicked. (this is for an administrator and so opening a small floater gives them more efficient access to the data that will be displayed). I now understand that because the ASP executes first, that...
1
2677
by: caine | last post by:
I want to extract web data from a news feed page http://everling.nierchi.net/mmubulletins.php. Just want to extract necessary info between open n closing tags of <title>, <categoryand <link>. Whenever I initiated the extraction, first news title is always "MMU Bulletin Board RSS Feed" with the proper bulletin's link stored, but not the correct news title being stored. Necessary info only appears within <itemand </itemwhich consists...
2
13269
by: learnyourabc | last post by:
For a webcrawler, you need to extract all links from the web page. For normal html anchor tags or any of the src and href attribute on the tag can be easily extracted using ihtmldocument. What about links inside of javascript function like below?? <HEAD> <SCRIPT language="JavaScript"> <!--hide function newwindow()
2
1840
by: tgmcnaughton | last post by:
I'm brand new to server-side scripting. I don't even know if javascript can do this. I would like a script running on my server to periodically login to and check my email account and each time it finds a new message with a particular identifying subjectline, it should extract the body of the message into a text variable and append it to an existing file already on the server. I can handle the parsing and the appending, but I don't know...
10
21585
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value by a javascript link to another page to check. my code is <a href="javascript:location.href='page_check.php' "Go check </a> and this work and open page_check.php
0
1837
by: Formula | last post by:
Hello everybody,because I am newbie in python two weeks only but I had programming in another languages but the python take my heart there's 3 kind of arrays Wow now I hate JAVA :) . I am working now on html process. So, I found a good class for getting html tag but I don't know how to use it I wrote this code for getting the tag A hopping some help please >>> <% import urllib from sgmllib import SGMLParser
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.