Question mark is creating line break

  • Thread starter Agent Michael Scarn
  • Start date
A

Agent Michael Scarn

Hello All,

After I submit a form it goes to a post page where I have a javascript
that creates one variable that has all of the element names from the
form listed out like so:

var1=var1&var2=var2&var3=var3

and so on...

the problem is when i try to add a question mark in front of this
variable its adding a line break like so:

?
var1=var1&var2=var2&var3=var3

Here is the Javascirpt that gets each element name from the previous
form just submitted and puts it into one variable with the '=' and '&'
symbols:

var myForm = parent.document.forms.<CFOUTPUT>#FORM_NAME#</CFOUTPUT>;
var elements = ""
var character = ""
for (i = 0; i < myForm.elements.length; i++) {
if (i > 0) {
elements = elements + "&" + myForm.elements.name + "=#" +
myForm.elements.name + "#";
}else{
elements = "?" + myForm.elements.name + "=#" +
myForm.elements.name + "#";
}
}


What Im trying to do with the end result is load it into a Ajax loader
to refresh part of a page like so:

var ajaxvar = "/admin/users/users.cfm" + elements;
parent.ajaxLoader(ajaxvar,'loader');

Any help would be great!

Thanks.


________________________
w. http://www.spymed.com
 
B

Bart Van der Donck

Agent said:
After I submit a form it goes to a post page where I have a javascript
that creates one variable that has all of the element names from the
form listed out like so:
var1=var1&var2=var2&var3=var3
and so on...

the problem is when i try to add a question mark in front of this
variable its adding a line break like so:

?
var1=var1&var2=var2&var3=var3

Here is the Javascirpt that gets each element name from the previous
form just submitted and puts it into one variable with the '=' and '&'
symbols:

var myForm = parent.document.forms.<CFOUTPUT>#FORM_NAME#</CFOUTPUT>;

That is no javascript. I suppose it's coming from your server language
that generates the js.
var elements = ""
var character = ""
for (i = 0; i < myForm.elements.length; i++) {
if (i > 0) {
elements = elements + "&" + myForm.elements.name + "=#" +
myForm.elements.name + "#";
}else{
elements = "?" + myForm.elements.name + "=#" +
myForm.elements.name + "#";
}
}


I can't simulate your result on WinXP IE 6.0.29 and FF 1.0.4. The code
appears to work fine here. I believe it should have something to do
with where you say

var myForm = parent.document.forms.<CFOUTPUT>...

where current script takes its data from parent. Sorry for mentioning
the obvious, but make sure your first element name doesn't start with a
line end.

You could use a regular expression to replace 'question mark followed
by \n' to 'question mark' in the beginning of a string:

alert ( '?\nSOMETHING'.replace(/^\?\n/,'?') );

But there is another problem. You should make sure to escape your
element names/values before compiling your query string:

alert ( escape('thiscontains?and&and=') );

Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top