View Full Version : Beetle I Need Your Help
morpheause
09-12-2002, 11:03 AM
Hi Beetle,
I have created an form with your validation script.
Know when you click on the send/submit button it redirects to another page.
The Question
Can I copy the Just One Text Field Value to the New Page.
I have attached the form page and the thanks page.
The field id that I would like to copy is called FullNames
:thumbsup:
beetle
09-12-2002, 03:30 PM
Well, without something server-side that can filter form GET/POST data, you can't prevent it from being sent with javascript. However, I have written a function that let's you access GET variables with javascript. Here's the function (orginally posted here (http://www.codingforums.com/showthread.php?s=&threadid=4555))function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
var g = parseGetVars();Ok, so how do we use this? on the 2nd page, simply use the get variable data to populate a field on the next pagedocument.forms[0].FullNames.value = g['FullNames']; That what you need?
zoobie
09-12-2002, 04:00 PM
If you need help from someone specific, we prefer you email them, junior member. :rolleyes:
shakib
11-25-2002, 02:48 PM
Originally posted by beetle
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
var g = parseGetVars();cool stuff beetle.
my only comments would be that, if you're using GET string's properly, I don't think the "name" part of the name/value pair should need to be unescaped (i.e. it shouldn't contain any characters that need url-encoding in teh first place). Also it might better taking the url to be parsed as an argument - just for the sake of portability.
cool stuff, sweet forum :)
RadarBob
11-25-2002, 03:42 PM
I do this to several fields. On the client side, I execute a function that triggers when the SUBMIT button is clicked. If certain conditions are met I set the fields disabled property to true. This prevents the field from going along for the ride to the server.
This technique also works for checkboxes, radio buttons, select options. For example, if you want the underlying 'value="xxxx" ' of an visually unchecked checkbox to get passed, just set 'checked="true" ' prior to actually sending the form.
CAVEAT: I've done this only with POST. I've never tried it with GET.
ConfusedOfLife
11-25-2002, 08:01 PM
Originally posted by zoobie
If you need help from someone specific, we prefer you email them, junior member. :rolleyes:
I'm one of the Matrix fans! :D
whammy
11-25-2002, 11:51 PM
Wow, that function is very similar to this one:
<script type="text/javascript">
<!--
function QueryString(str){
var q = window.location.search;
var foundValue = ""
if(q.length > 1){
this.q = q.substring(1, q.length);
}
this.keyValuePairs = new Array();
if(q){
for(var i = 0; i < this.q.split("&").length; i++){
this.keyValuePairs[i] = this.q.split("&")[i];
if(this.keyValuePairs[i].split("=")[0] == str){
foundValue = unescape(this.keyValuePairs[i].split("=")[1]);
}
}
}
return foundValue;
}
//-->
</script>
I just modified some code I found to make it work like "Request.QueryString()" in ASP. :)
Yours looks a bit shorter and more elegant though... although I haven't tested it to see if it works exactly the same way.
This contains some of the features shakib was talking about though... but I'm gonna have to "elegantize" the code above some more when I get a chance. ;)
beetle
11-26-2002, 12:22 AM
It doesn't work the same way. Mine puts ALL the GET variables into an associative array variable that you choose. (like PHP's $_GET). The code you posted retrieves/returns the value of a GET variable based on a name passed to the function (as you said, like ASP's Request.QueryString())
So, in short, my function runs once and puts ALL the GET values into an array. Your function is run whenever a specific variable is requested from the GET data.
whammy
11-26-2002, 12:23 AM
Yup, that's exactly what my function does... I am still pondering the two similar functions for different types of requests (especially since they seem to be related to comfortability (I think I just made that word up, lol) with a preferred server-side language). I can dig that, though. ;)
Actually the function above puts them all into an array as well, it just looks to see if anything matches what's passed to the function.
That's one of the things I can improve upon in the script though (and you are partially responsible for educating me about this, from reading previous posts... one of glenngv's comes to mind hehe) - to break out of the loop when something does match (and not within the loop, but define that from the beginning). I just haven't messed with it yet in this particular script.
I learn pretty fast for an "old man", but I'm still fairly new to programming (only a couple of years experience if you discount BASIC as a kid)... so all constructive input helps. :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.