1

Possible Duplicate:
How can I get query string values?
grab query string using javascript

I have one Form URI, I need to read a specific ATTRIBUTE value. and set that value to one of the Same Form-filed.

Example:-"formFieldName=UXCopy%3Abody&FCKAssetId=Variables.ContentDetails%3Aid&fielddesc=Body&FCKName=homecopy&AssetType=UXPage&StartItem=1299862617913&FCKAssetType=UXCopy&cs_environment=addref&pagename=OpenMarket%2FXcelerate%2FActions%2FNewContentFront&embedtype=link&adidiii=ssssssss&childtypes=UXDocument%2CUXEmbed%2CUXGoogleMap%2CUXImage%2CUXSocialMediaLink%2CUXPage&IFCKEditor=true&title=New&cancelpage=OpenMarket%2FXcelerate%2FActions%2FAddRefFront&assetid=Variables.assetid"

I want to read adidiii Value and set this value to one of the Same Form Filed.

Community
  • 1
  • 1

2 Answers2

0
var newURI = oldURI.replace(/&adidiii\=.+[&$]/, "&adidiii=" + encodeURIComponent(**WhateverThisSameFormFieldIs**) + "&")

If you just want to get a parameter from the uri do this:

function getURIParam(URI, param)
{
    var match = URI.match(new RegExp("[\?&]" + param + "=([^&]+)"));
    return match[1] ? decodeURIComponent(match[1]) : null;
}
Delta
  • 4,308
  • 2
  • 29
  • 37
  • Can you help me how to get individual ATTRIBUTE values from URI, Do we have any js methods to get the value by passing ATTRIBUTE name. "document.URL." –  Oct 23 '12 at 06:54
  • Don't think so buddy, you're gonna have to stick with regular expressions really – Delta Oct 23 '12 at 06:58
  • i just tried with above code am getting this error "Cannot call method 'match' of undefined". do i need to explicitly define "match" method. am newbie in JavaScript, thanks in advance –  Oct 23 '12 at 07:46
  • You need to pass the uri to the function. – Delta Oct 23 '12 at 09:44
  • Finally i have return some js function,its working as per my requirement. thanks for your support –  Oct 23 '12 at 10:37
0

Use the following method to process the URL and return the values you are expecting out of it.

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

If you want to get the value of adidiii use the following code.

var field = getUrlVars()["adidiii"];

alert(field);

Hope this will help you.

Anil Kumar C
  • 1,604
  • 4
  • 22
  • 43