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. Advertisements

  2. (Rob) writes:

    PLEASE use a descriptive subject. While cute, this isn't it.
    Does it append that to the "action" attribute of the form element, or
    is it part of the normal form submission?
    How? When?
    Parent window of the new window (i.e., the current) or parent window
    of the current window?
    Good, so that works.
    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;

    window.opener.document.forms['taggingUI'].elements[var2].value +=
    selvalue+', ';
    So the new window is just a way of doing a fetch without killing the
    page.

    Unless you use Mozilla.
    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:
    Ah, will you pay for it? :)
    (Damn! Too late now!)

    /L
     
    Lasse Reichstein Nielsen, May 17, 2004
    #2
    1. Advertisements

  3. Rob

    Ivo Guest

    Is this done by the form itself with the common get method, or do you do
    this with javascript?
    You mean a popup? How?
    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;

    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
    What isn't?
     
    Ivo, May 18, 2004
    #3
  4. Rob

    Lee Guest

    Rob said:
    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.