...

View Full Version : Printing the last 4 digits when using getParams



isaaclloyd
03-26-2005, 07:15 PM
I am trying to figure out how to print the last 4 digits instad of the whole thing when the page prints the paramiters, or params, whatever... Heres the script:





<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
// End -->
</script>



<SCRIPT LANGUAGE="JavaScript">
quantity = unescape(params["ordernumber"]);
document.write(ordernumber);
</SCRIPT>



Any comments or suggestions would greatly be apreciated. Thanks.


~Isaac Lloyd~

Mr J
03-27-2005, 12:31 AM
Please try the following

<script language="javascript">
<!--
dataPassed=0

if (location.search.length > 0){
url = unescape(location.search.substring(1))

str=url.substring(url.length-4,url.length)

alert(str)
}

// -->
</script>

isaaclloyd
03-27-2005, 12:41 AM
*EDIT* NM, I figured it out. Thanks for your time.


in which par of my script would I put that? and what is that printing out? the whoe URL? See I have a lot more Params that I don't want to show only 4 digits. Example:



<SCRIPT LANGUAGE="JavaScript">
quantity = unescape(params["firstname"]);
document.write(firstname);

quantity = unescape(params["lastname"]);
document.write(lastname);

quantity = unescape(params["creditcardnumber"]);
document.write(creditcardnumber); <--- This one show only the last 4 digits.


</SCRIPT>


Thanks for your time and help.

~Isaac Lloyd~

Philip M
03-27-2005, 10:09 AM
quantity = unescape(params["creditcardnumber"]);
quantityA = quantity.substring(quantity.length-4,quantity.length);
quantityA="XXXX XXXX XXXX " + quantityA;
document.write(quantityA); <--- This one show only the last 4 digits.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum