i am rewriting my url and category name passing in to url. Now i am creating Url Friendly String using JS function is:
function getUrlFriendlyString(str)
{
// convert spaces to '-'
//alert(str);
str = str.replace(/ /g, "-");
// Make lowercase
str = str.toLowerCase();
// Remove characters that are not alphanumeric or a '-'
str = str.replace(/[^a-z0-9-]/g, "");
// Combine multiple dashes (i.e., '---') into one dash '-'.
str = str.replace(/[-]+/g, "-");
return str;
}
now on HTML page this JS function is giving a string value in JS like
<? $cat_name= 'Personalized Chocolates / Gift'; ?>
<script>var url=getUrlFriendlyString("<?=$cat_name;?>");</script>
i want to pass var url value in html tag href like that
<a href="<?PHP echo SITE_URL;?>/category/<script>document.write(url);</script>/<?=$data_2['cat_id'];?>"
but
<script>document.write(url);</script>
not giving their value and coming url is like that
http://localhost/ecom/category/<script>document.writeln(url);</script>/105
required url is
http://localhost/ecom/category/personalized-chocolates-gift/105
any idea how i can show proper url using js string?
i can save var url value in PHP variable