SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    birmingham, uk
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return statement within javascript

    Hi All,

    I have a problem! I am unable to return a value from a javascript window. I would like to pass the value from the child window back to the main window. Does anybody know how? the following is the code i have tried to use however it was unsuccessful




    <HTML>
    <HEAD>
    <title>ddd</title>

    <script type="text/javascript" language="javascript">
    function go()
    {

    OpenWindow=window.open("", "newwin", "height=250,width=300," +
    "toolbar=yes,scrollbars=yes,menubar=no");
    OpenWindow.document.write("<TITLE>Title Goes Here</TITLE>");






    var S =document.forms['testform'].testselect.selectedIndex;
    var example =document.forms['testform'].testselect.options[S].value;
    OpenWindow.document.write (example);
    //alert("the prize you chose is a " + example);
    return example;
    }

    </script>


    </HEAD>
    <body>
    <form name="testform" onsubmit= "h=go()">
    <select name="testselect">
    <option value="first">first option</option>
    <option value="second">second option</option>
    <option value="third">third option</option>
    <option>your browser can't handle this script</option>
    </select>
    <input type="submit" value="submit the form"/>
    <p>the value of my returned variable is h </p>
    </form>



    </body>

    </HTML>

    humaira

  2. #2
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont know javascript very well, but is // a comment? Because if it is:
    //alert("the prize you chose is a " + example);
    wont work .

  3. #3
    SitePoint Zealot gohankid77's Avatar
    Join Date
    Jun 2004
    Location
    United States
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tested. // denotes a single-line comment and /* ... */ denotes a multi-line comment (I think). Most people know that IE sucks and that is what I was using. As for the problem: get rid of the // in //alert.... or put alert.... on a new line.

    Code:
    OpenWindow.document.write (example);
    alert("the prize you chose is a " + example);
    return example;
    or

    Code:
    OpenWindow.document.write (example);
    //
    alert("the prize you chose is a " + example);
    return example;
    I recommend the first choice because I don't know if the value will be stored and returned properly, if at all, in the second choice.
    Gohan (Mmm... Yummy!)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •