Urgent problem, repeat, Urgent problem.

Discussion in 'Javascript' started by Rob, May 17, 2004.

  1. Rob

    Rob Guest

    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
     
    Rob, May 17, 2004
    #1
    1. Advertising

  2. (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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, May 17, 2004
    #2
    1. Advertising

  3. Rob

    Ivo Guest

    "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!
     
    Ivo, May 18, 2004
    #3
  4. Rob

    Lee Guest

    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?
     
    Lee, May 18, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. frank

    Repeat DataGrid?

    frank, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    424
    frank
    Jul 11, 2003
  2. Jane sharpe

    How do I repeat pages.....

    Jane sharpe, Dec 17, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    467
    Jane sharpe
    Dec 18, 2003
  3. SamIAm
    Replies:
    5
    Views:
    5,669
    S. Justin Gengo
    Jan 7, 2004
  4. cmeek1_1999
    Replies:
    3
    Views:
    4,861
    cmeek1_1999
    Sep 27, 2008
  5. gp
    Replies:
    0
    Views:
    106
Loading...

Share This Page