By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Question mark is creating line break

P: n/a
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[i].name + "=#" +
myForm.elements[i].name + "#";
}else{
elements = "?" + myForm.elements[i].name + "=#" +
myForm.elements[i].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

Sep 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Agent Michael Scarn wrote:
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[i].name + "=#" +
myForm.elements[i].name + "#";
}else{
elements = "?" + myForm.elements[i].name + "=#" +
myForm.elements[i].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,

--
Bart

Sep 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.