Link to home
Start Free TrialLog in
Avatar of oconnork00
oconnork00Flag for United States of America

asked on

Parsing data to a webpage

Hi all,

I use a email marketing program called getresponse.com
I have it so that when the user inputs their email address, first name and a ID number they submit it and sign up to my newsletter. Now I have it set so that the data appears in the URL at the top when it directs them to the next window after confirmation.

What I would like to know is if there is a way I can parse this information (correct term here?) so that when they are at the confirmation web page it will say "Dear XXXX(person's name)" instead of dear friend

Thanks in advance guys

Kevin
Avatar of nimaig
nimaig
Flag of India image

Are you using any server-side technology (asp/jsp/cgi/php ...) .. or you want to achive it using plain javascript?

If you are using Javascript, and your url has the the Persons name like

http://www.urwebsite.com/confirm.html?personName=Kevin 

you can have a method like

function getParamFromURL(paramName )
{
  var regexS = "[\\?&]"+paramName +"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

and then get the value from the url using

var personName = getParamFromURL( 'personName' );

Once you get the personName, you can use the same to display in browser.
Avatar of sundaramkumar
sundaramkumar

If you are using PHP language in server side, then you use like this

$person = $_REQUEST['name'];

and the print on the screen like
echo "Dear" . $person

For that you can send your data in post as well as a querystring. based upon that you have to change this
$person = $_REQUEST['name'];

Avatar of oconnork00

ASKER

Hi nimaig:

Your solution is like what I am looking for... Can I implement this into my html?
What I wanted to do was have this:

Dear 'your javascriptcode'

this will produce
Dear Kevin

Will your code above do this?

Cheers and thanks all for the help
ASKER CERTIFIED SOLUTION
Avatar of nimaig
nimaig
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi that looks great,
I want the parsed result to be YourAge

Ao, is this correct>

<script language="javascript">

function getParamFromURL(paramName )
{
  var regexS = "[\\?&]"+paramName +"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function displayName()
{
      var personName = getParamFromURL('YourAge');
      var spanObj = document.getElementById("spanName");
      spanObj.innerHTML = YourAge;
}
</script>
<body onload="displayName()">
Dear <span id="spanName" name="spanName"></span>,


Thanks

function displayName()
{
      var YourAge = getParamFromURL('YourAge');
      var spanObj = document.getElementById("spanName");
      spanObj.innerHTML = YourAge

This seems to do it... Looks ok?
Thats correct
Hi nimaig,

Sorry to ask this after closing the question, but just one more thing on that code.
Once parsed, it returns the value that I want, YourAge however it has a space before this...

Eg.
<a href="http:// YourAge
There is a space between // and YourAge

What am I doing wrong here?

Thanks a million

Kevin
There may be a space in the parameter value itself. Just use this trim() method to remove any leading and trailing spaces.

Ex.
var personName = trim(getParamFromURL('YourAge'));


function trim( newStrValue ) {
      var objRegExp = /^(\s*)$/;
      //check for all spaces
      var strValue = new String(newStrValue);
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
    //check for leading & trailing spaces
         objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
         if(objRegExp.test(strValue)) {
          //remove leading and trailing whitespace characters
             strValue = strValue.replace(objRegExp, '$2');
    }
        return strValue;
}