[Javascript] Extract portion of URL and place in form field

Muchacho, Laurent (TWIi London) LMuchacho at twii.net
Tue May 21 11:08:57 CDT 2002


Hi Colin 

I found that function a while ago that might help you 
you just need to call the function like that or by any other way you know

>This is the string...
>http://www.mysite.com/thanks.html?cbreceipt=Z54HKPT7
>
>I'm after the Z54HKPT7.

<a href="javascript:QueryString('cbreceipt')"></a>

and you will get the Z54HKPT7

there is the function 

function QueryString(param){

  var begin,end;
  if(self.location.search.length>1)
  {
    begin=self.location.search.indexOf(param) +param.length+1;
    end=self.location.search.indexOf("&",begin);
    if(end==(-1)) end=self.location.search.length;
    return(self.location.search.substring(begin,end));
  }
  else if(self.location.hash.length>1)
  {
    begin=self.location.hash.indexOf(param) +param.length+1;
    end=self.location.hash.indexOf("&",begin);
    if(end==(-1)) end=self.location.hash.length;
    return(self.location.hash.substring(begin,end));
  }
  else return("");

}


Laurent 


-----Original Message-----
From: Colin Cochrane [mailto:colin at vfs.com]
Sent: 21 May 2002 16:33
To: javascript at LaTech.edu
Subject: Re: [Javascript] Extract portion of URL and place in form field


>This is the string...
>http://www.mysite.com/thanks.html?cbreceipt=Z54HKPT7
>
>I'm after the Z54HKPT7.
>
>How would I do this?

// Use split.
var string="http://www.mysite.com/thanks.html?cbreceipt=Z54HKPT7";
var getit= new Array();
 getit=string.split("=");
alert(getit[1]);
var result=getit[1];
window.document.yerform.fieldname.value=result;

// sorry about that.

Of course, you'd need to send the result to your form, not just alert it.

cdc


Colin Cochrane
Head Instructor
Vancouver Film School New Media
http://www.vfs.com/
Tel: (604) 685-6331 Ext 209
Fax: (604) 685-6308

Vancouver Film School. Creative. Disciplined. Focused.


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


DISCLAIMER - The preceding e-mail message (including any attachments)
contains information that may be confidential, may be protected by the
attorney-client or other applicable privileges, or may constitute non-public
information.  It is intended to be conveyed only to the designated
recipient(s) named above.  If you are not an intended recipient of this
message, or have otherwise received it in error, please notify the sender by
replying to this message and then delete all copies of it from your computer
system.  Any use, dissemination, distribution, or reproduction of this
message by unintended recipients is not authorized and may be unlawful. The
contents of this communication do not necessarily represent the views of
this company.



More information about the Javascript mailing list