Forum Moderators: open
What I would probably do is use the replace() function and a simple regular expression.
orig = document.referrer;
chgd = orig.replace(/&/, '+');
Thanks. I tried the following but I'm at a loss as to the correct javascript.
I'm trying to send the HTTP_REFERER via a form as noted below.
The script that handles the form can not parse (&), thus my need to change those to a (+) plus sign.
Below is a test of what I'm accessing, but I still get an error, don't know why..
-------------------------------------------
<head>
<script type="text/javascript">
function replace()
{orig = document.referrer;
chgd = orig.replace(/&/, '+');
}
<script>
</head>
<body>
<form>.....blah, blah
<input type=hidden name="SO_GL" value='<?xml version="1.0" encoding="iso-8859-1"?><SO_GL><GLOBAL_LIST><NAME>SITE_LIST_EXTERNAL_REMARK</NAME><LIST_ELEMENT><CODE>HTTP REFERER</CODE><LIST_VALUE>
<script><document.write("referrer()")></script>
</LIST_VALUE></LIST_ELEMENT></GLOBAL_LIST></SO_GL>'>
<input type="submit" value="Submit"></FORM>
</body>
--------------------------
Regards,
Douglas
Try something like this...
<head>
<script type="text/javascript">
<!--
function replace()
{
var orig = document.referrer;
var chgd = orig.replace(/&/, '+');
var completestring = '<?xml version="1.0" encoding="iso-8859-1"?>' + '<SO_GL><GLOBAL_LIST><NAME>SITE_LIST_EXTERNAL_REMARK<\/NAME>' + '<LIST_ELEMENT><CODE>HTTP REFERER<\/CODE>' + '<LIST_VALUE>'+chgd+'<\/LIST_VALUE>' + '<\/LIST_ELEMENT><\/GLOBAL_LIST><\/SO_GL>';
var the_xml_input_obj = document.getElementById('the_xml_input');
the_xml_input_obj.value = completestring;
alert(the_xml_input_obj.value);
}
-->
</script>
</head>
<body>
<form>.....blah, blah
<input type=hidden name="SO_GL" value='' id="the_xml_input">
<script type="text/javascript">replace();</script>
<input type="submit" value="Submit"></FORM>
</body>
It loads the xml string into a variable and concatenates in the referrer value. Then pops it into the value of the input.
This would probably be better as a server side thing though. Do you have access to PHP or ASP? I can provide sample code for PHP.
<?php echo $_SERVER['HTTP_REFERER'];?><input type=hidden name="SO_GL" value='<?xml version="1.0" encoding="iso-8859-1"?>
<SO_GL><GLOBAL_LIST><NAME>SITE_LIST_EXTERNAL_REMARK</NAME>
<LIST_ELEMENT><CODE>HTTP REFERER</CODE>
<LIST_VALUE></LIST_VALUE>
</LIST_ELEMENT></GLOBAL_LIST></SO_GL>'>
<input type="submit" value="Submit"></FORM>
This is what I have so far
-------- form.js ------------------
function replace(){
var orig = document.referrer;
var chgd = orig.replace(/&/g, +); //replace the & sign to a + sign
var chgd = orig.replace(/&/g, +); //replace any & sign to a + sign
document.myform.SO_GL.value = "<?xml version="1.0" encoding="iso-8859-1"?><SO_GL><GLOBAL_LIST><NAME>SITE_LIST_EXTERNAL_REMARK</
NAME><LIST_ELEMENT><CODE>HTTP REFERER</CODE><LIST_ELEMENT><CODE>UD1</
CODE><LIST_VALUE><!--#echo var="server_addr"--></LIST_VALUE></
LIST_ELEMENT><LIST_ELEMENT><CODE>UD2</CODE><LIST_VALUE><!--#echo var="
script_filename" --><!--#echo var="QUERY_STRING" --></LIST_VALUE></
LIST_ELEMENT><LIST_ELEMENT><CODE>UD3</CODE><LIST_VALUE>USERIP: <!--#echo var
="remote_addr" --></LIST_VALUE></LIST_ELEMENT><LIST_ELEMENT><CODE>UD4</
CODE><LIST_VALUE>USERHOST: <!--#echo var="REMOTE_HOST" --></LIST_VALUE></
LIST_ELEMENT><LIST_ELEMENT><CODE>UD5</CODE><LIST_VALUE>+chgd+</LIST_VALUE></
LIST_ELEMENT></GLOBAL_LIST></SO_GL>"
}
function formValidator (theForm) {
replace();
}
-----------------------------------
On the web page I call it via:
<head>
<script language="JavaScript" src="http:/[smilestopper]/www.example.com/form.js" type="text/javascript"></script>
</head>
Then from the <body>
<Form name="myform" method="POST" onSubmit="return formValidator(this)">
<input type=hidden name="SO_GL" value="">
Any help is welcomed, I don't know how to make it work, but I'm sure there is a way to parse information into the form.
Thanks,
Douglas
------------------------------
<HEAD>
<script type="text/javascript">
<!--
function replace()
{
var orig = document.referrer;
var chgd = orig.replace(/&/, '+');
var chgd = orig.replace(/&/, '+');
var completestring = '<?xml version="1.0" encoding="iso-8859-1"?
><SO_GL><GLOBAL_LIST><NAME>SITE_LIST_EXTERNAL_REMARK<\/
NAME><LIST_ELEMENT><CODE>http_referrer<\
/CODE><LIST_VALUE>'+chgd+'<\/LIST_VALUE><\/LIST_ELEMENT><\/GLOBAL_LIST><\/
SO_GL>';
var the_xml_input_obj = document.getElementById('the_xml_input');
document.abstravel.SO_GL.value = completestring;
}
window.onload = replace;
-->
</head>
<body><form...etc>
</script>
<input type=hidden name="SO_GL" id='the_xml_input' value="<script type="text
/javascript">replace();</script>">
</form></body...etc>