SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Send selected values to an iFrame

    I have a listbox that populates 2 fields.

    How can I get the output from this form to be sent to an iFrame.
    I'm trying to see how to set these input fields into variables.

    Here's a bit of what I have.

    Code:
    <script type="text/jscript">
    function passValue() {
        var ddl = document.getElementById("ddlName");
        var index = ddl.selectedIndex;
        document.getElementById("txtValue").value = ddl.value;
        document.getElementById("txtName").value = ddl.options[index].text;
    }
    </script>
    <P>
    Course Name <input type="text" id="txtName" readonly="readonly"/><BR>

    Course ID input type="text" id="txtValue" readonly="readonly"/><br>
    <P>

    I load values from a database into a ListBox. Then make a selection.

    <select size= 5 id="ddlName" onchange="passValue()">

    The selected values are correctly placed into the input fields.
    I'm trying to get the 2 values "txtName" and "txtValue" sent to the iframe also.

    <iframe src="http://xxx.net/iPage.html" width="600" height="400"> </iframe>

    The iFrame has 2 input fields of the same names.

    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    // first iframe in document
    frames[0].document.getElementById('txtValue').value = ddl.value;
    // iframe with ID
    document.getElementById(iframeID).contentDocument.getElementById('txtValue').value = ddl.value'

  3. #3
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dogFang:

    I didn't get it to work. All I was thinking of was a way to possibly modify the function so that it posted the results to the iFrame also, and a way to have the iFrame access the var data.

    Code:
    function passValue() {
        var ddl = document.getElementById("ddlName");
        var index = ddl.selectedIndex;
        document.getElementById("txtValue").value = ddl.value;
        document.getElementById("txtName").value = ddl.options[index].text;
    }
    
    Thanks

  4. #4
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI:

    The code works in IE and Opera. The problem was in Firefox.

    I needed to add an ID to the iFrame, and make the input on the iFrame like
    <input id="txtValue" type="text">

    Thanks for your help.


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
  •