f



Urgent problem, repeat, Urgent problem.

I have a form - when you click the submit button, it appends a
variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable)

It also opens a new page. Now, that some_dynamic_variable is actually
the name of a form element on the parent window.

On the new page, I have this javascript:
----
var var2 = location.search.substring(9);
document.write(var2)
----
This will print out some_dynamic_variable

I then have the following code 

----
function sendValue(var1, var2){
var selvalue = eval('selectform.' + var1 + '.value');
window.opener.document.taggingUI.var2.value += selvalue + ', ';
window.close();
----

var1 is no problem. var2 isn't working. I've tried a whole bunch of
things, nothing works!! I need to insert var2 in that spot, and it's
urgent.

If you have an idea, please let me know....

Thanks!
djsphynx insert the at symbol hot mail dot com
0
djsphynx
5/17/2004 10:44:36 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

3 Replies
812 Views

Similar Articles

[PageSpeed] 36

djsphynx@hotmail.com (Rob) writes:

PLEASE use a descriptive subject. While cute, this isn't it.

> I have a form - when you click the submit button, it appends a
> variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable)

Does it append that to the "action" attribute of the form element, or 
is it part of the normal form submission?

> It also opens a new page. 

How? When?

> Now, that some_dynamic_variable is actually the name of a form
> element on the parent window.

Parent window of the new window (i.e., the current) or parent window
of the current window?

> On the new page, I have this javascript:
> ----
> var var2 = location.search.substring(9);
> document.write(var2)
> ----
> This will print out some_dynamic_variable

Good, so that works.

> I then have the following code 
>
> ----
> function sendValue(var1, var2){
> var selvalue = eval('selectform.' + var1 + '.value');

Never use "eval" to acces properties of object. There are safer and
more efficient ways to do that (as for almost any use of "eval" - just
don't use it!).

 var selvalue = document.forms['selectform'].elements[var1].value;

<URL: http://jibbering.com/faq/#FAQ4_40 >

> window.opener.document.taggingUI.var2.value += selvalue + ', ';

 window.opener.document.forms['taggingUI'].elements[var2].value += 
   selvalue+', ';

> window.close();

So the new window is just a way of doing a fetch without killing the
page.

> ----
>
> var1 is no problem. 

Unless you use Mozilla.
<URL: http://jibbering.com/faq/#FAQ4_41 >

> var2 isn't working. 

See <URL: http://jibbering.com/faq/#FAQ4_39 >

> I've tried a whole bunch of things, nothing works!! 

I was about to suggest you read a book about Javascript, but just
picking any book is likely to make matters worse :) 


Read the FAQ! All og it! it's all good advice.
(Now we know that you know, and so we will expect you to not ask
questions answered by the FAQ :P )

And to learn about JavaScript, try this:
 <URL:http://www.crockford.com/javascript/survey.html>
(Note to author: NaN is still a falsey value! :)

> I need to insert var2 in that spot, and it's urgent.

Ah, will you pay for it? :) 
(Damn! Too late now!)

/L
-- 
Lasse Reichstein Nielsen  -  lrn@hotpop.com
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'
0
Lasse
5/17/2004 10:57:23 PM
"Rob" wrote
> I have a form - when you click the submit button, it appends a
> variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable)

Is this done by the form itself with the common get method, or do you do
this with javascript?

> It also opens a new page.

You mean a popup? How?

> Now, that some_dynamic_variable is actually
> the name of a form element on the parent window.
>
> On the new page, I have this javascript:
> ----
> var var2 = location.search.substring(9);
> document.write(var2)
> ----
> This will print out some_dynamic_variable
>
> I then have the following code
>
> ----
> function sendValue(var1, var2){
> var selvalue = eval('selectform.' + var1 + '.value');

Needless eval, where does it come from? What is selectform? I 'm asking not
only because I don't know but also many browsers won't know, hence occurs
occur. My human instinct tells me it 's a reference to a form. You need to
tell the browser that in a more formal way. I 'd need to see more code (an
url?) to say exactly how. It 's probably along the lines of:

var selvalue = document.forms[ 'selectform' ].elements[ var1 ].value;


> window.opener.document.taggingUI.var2.value += selvalue + ', ';

Ay ay. var2 is clearly taken just as literally as taggingUI in this syntax,
but what you want its value. Take a good look at the quotes around
selectform and the absence of quotes around var1 above. That 's how it 's
done.
What is taggingUI? The id of something in the opener document? Then use
getElementById, like so:

window.opener.document.getElementById( 'taggingUI' )

Or it 's the form you mentioned, right? Then

window.opener.document.forms[ 'taggingUI' ]

is even better supported among browsers.
These are just some urgent pointers, but you need to take some time to read
up on some basics and the wider picture (beyond IE).
HTH
Ivo

> window.close();
> ----
>
> var1 is no problem. var2 isn't working.
> I've tried a whole bunch of
> things, nothing works!! I need to insert var2 in that spot, and it's
> urgent.

What isn't?

> If you have an idea, please let me know....
>
> Thanks!



0
Ivo
5/17/2004 11:09:45 PM
Rob said:

>var1 is no problem. var2 isn't working. I've tried a whole bunch of
>things, nothing works!! I need to insert var2 in that spot, and it's
>urgent.
>
>If you have an idea, please let me know....

Now that you've got a couple of answers, I'd like to hear how
you managed to get yourself into an "urgent" coding situation
without knowing something this basic?  Is this for a class?
How long have you been putting this off?

0
Lee
5/18/2004 12:05:47 AM
Reply: