www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need help with forms interacting with frames

  1. #1
    Join Date
    Jun 2006
    Posts
    3

    Need help with forms interacting with frames

    I have a page that is divided into two frames:

    HTML Code:
    <frameset cols="20%,*">
    	<frame name="menu" id="menu" src="left.html" />
    	<frame name="main" id="main" src="page2.html" />
    </frameset>
    On the left (menu), I have this form:

    HTML Code:
    <form name="leftFrom" id="leftForm" method="post" action="...">
    	<input type="text" name="textBoxLeft1" /><br /><br />
    	<input type="text" name="textBoxLeft2" />
    </form>
    On the right (main), I have a form with radio buttons. I need to get the button selected to show up in texBoxLeft1. Here's the code I have:

    HTML Code:
    <script type="text/javascript" charset="ISO-8859-15">
    //create funtions to check radio and check boxes for user entries ************************
      function checkingRadio(radiogrp) {
        var ix;
        var foundIt = false;
        for (ix = 0; ix < radiogrp.length; ix++) {
          if (radiogrp[ix].checked) {
            foundIt = true;
            break;
          }
        }
        return (foundIt)? ix : -1;
      }
      
      function radioResults(radiogrp, target) {
        var ix = checkingRadio(radiogrp);
        if (ix >= 0) {
          target.value = "Radio button: #" + (ix + 1);
        } else {
          target.value = "No radio button has been selected.";
        } 
      }
      
      function checkingCheckBoxes(formSrch, target) {
        var cbIdx = 0;   // checkbox count
        var foundIt = false;
        var strResult = "";
        for (var ix = 0; ix < formSrch.length; ix++) {
          if (formSrch.elements[ix].type == "checkbox") {
            cbIdx++;
            if (formSrch.elements[ix].checked) {
              foundIt = true;
              strResult += cbIdx + " ";
            }
          }
        }
        if (foundIt) {
          target.value = "Checkboxes: " + strResult;
        } else {
          target.value = "No checkbox has been selected";
        }
      }
      //*******************end of radio and checkBox input requests**************************
    </script>
    
    <form name="mainForm" id="mainForm" method="post" action="default.asp">
    	<!--adding text boxes to form-->
    	<!-- added onchange to convert any lower case letters in textBox1 to uppercase upon first action elsewhere -->
    	U/L case:<input type="text" name="textBox1" size="20" onchange="this.value =  this.value.toUpperCase();" />&nbsp;&nbsp;
    	<input type="text" name="textBox2" />&nbsp;&nbsp;
    	<input type="text" name="textBox3" /><br clear="all" /><br />
    	<!--adding radio buttons to form-->	
    	<input type="radio" id="radioButton" name="radioButton" value="val1" /><br />
    	<input type="radio" id="radioButton" name="radioButton" value="val2" checked="checked" /><br />
    	<input type="radio" id="radioButton" name="radioButton" value="val3" /><br clear="all" /><br />
    
    	<!--Start buttons-->
    	<input type="button" id="button2" name="button2" value="radioCheck" onclick="radioResults(document.mainForm.radioButton, parent.menu.leftFrom.textBoxLeft1);" /> <br />
    
    </form>
    But it's not working. Can anyone see what I'm doing wrong?

    Thanks in advance.

  2. #2
    Join Date
    Jun 2006
    Location
    Netherlands
    Posts
    8
    for the onclick event you should use the following:

    Code:
    onclick="radioResults(document.mainForm.radioButton,window.top.menu.document.leftForm.textBoxLeft1);
    I always recommend that you go to the top frame first, but that is just a matter of personal style I think. You then go to the right frame and then to the document of that frame.
    You can think of it in this way, the "window.top.menu" gives you the complete <html> tag, while "window.top.menu.document" gives you only the "body" tag.

    You also made a typo in the name of the form I think.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles