Jump to content

Transfer multiple select field in Iframe to parent on parent submit


Recommended Posts

I have a form in an iframe in a parent form.

The iframe has a multiple select box....

 

I am trying to transfer the Iframe fields to the parent form on parent form submit.

All works fine for text fields, but the multiple select field do not $_Post the multiple selected values, and only the first selected option in the form....

 

What am I doing wrong?

 

function fillValues(form){
var iElements=document.getElementById('iframe_id').contentWindow.document.forms['iframe_name'].elements, e, i=0;
while(e=iElements[i++]){
form[e.name].value=e.value;
}
}

This only transfer the first selected option in the multiple option field.

 

Any help?

 

The Parent Form:

<head>
<script type="text/javascript">
function fillValues(form){
var iElements=document.getElementById('iframe_id').contentWindow.document.forms['iframe_name'].elements, e, i=0;
while(e=iElements[i++]){
form[e.name].value=e.value;
}
}
</script>
</head>
<body>
<?
print "<pre>";
print_r($_POST);
print "</pre>"; 
if($_POST){
    $workStyle = $_POST['multiselect'];
    var_dump($workStyle);
    // Setting up a blank variable to be used in the coming loop.
    $allStyles = "";
    // For every checkbox value sent to the form.
    foreach ($workStyle as $style) {
    // Append the string with the current array element, and then add a comma and a space at the end.
    $allStyles .= $style . ", ";
    }
    $allStyles = substr($allStyles, 0, -2);
    echo '<br>The List: '.$allStyles;    
}

?>
<form action="<?=$root?>/member/bl_select_f.php"  method="post" onsubmit="return fillValues(this)">
<input type="text" name="MainFfield" value="MainForm">
<input type="hidden" name="banner1" value="">
<input type="hidden" name="banner_name_2" value="">
<input type="hidden" name="multiselect[]" value="">

<iframe name="theselect" id="iframe_id" src="<?=$root?>/member/test1.php" height="550" width="943"> 
</iframe>
<center>TEST<br>
<input type="submit" name="blistin" id="blistin" value="Submit">
<br>
TEST</center>
</form>
</body>

The Iframe:

<form name='iframe_name' id='iframe_id' method='post' action=''>
<input type="text" name="banner1" value="IFRAME BOOM 1">
<input type="text" name="banner_name_2" value="IFRAME BOOM 2">
<select id="multiselect_groups" name="multiselect[]" class="multiselect" multiple="multiple">
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="Maybe">Maybe</option>
</select>
 </form>
Edited by StefanRSA
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.