PDA

View Full Version : Submitting Form using popup and transferring values


Agent009
01-28-2008, 04:02 PM
Hai, I'm trying to submit a form using a popup, and transfer one of the values from the popup window to the main window for processing. This is what I have so far.

<?php
// Data queried before here, let use select a tool from list below
$tool_list = '<select name="tool_list">';
$tool_list .= '<option value = "0" >Select Lockpicking Tool</option>';
for( $i = 0; $i < count($info); $i++ ){
$tool_list .= '<option value = "'.$info[$i]['item_id'].'">' . $info[$i]['item_name'] . '</option>';
}
$tool_list .= '</select>';
?>
<SCRIPT LANGUAGE="JavaScript"><!--
function gettoolid(tool)
{
// Suppose to get the id of the selected tool from the list
this.toolid = document.popupForm.tool.options[document.popupForm.tool.selectedIndex].value;
return this.toolid;
}
function copyForm() {
// Suppose to send the selected item value back to main form and submit the form.
opener.document.lockpick.tool_id.value = gettoolid(document.popupForm.tool_list.value);
opener.document.lockpick.submit();
window.close();
return false;
}
//--></SCRIPT>
<body>
<FORM NAME="popupForm" onSubmit="return copyForm()">
<table width="100%" cellspacing="3" cellpadding="3">
<tr>
<td align="center">Select Lockpicking Tool<br><br><?=$tool_list;?><br><br>
<input type="button" name="lockpick_chest" value="Lockpick Chest!" onClick="copyForm()">
</td>
</tr>
</table>
</FORM>

But the form is not being submitted. If I take this part out

opener.document.lockpick.tool_id.value = gettoolid(document.popupForm.tool_list.value);

It dose sumbit, but I really need to send the item id back to the main form for processing. Any help on this?

Agent009
01-29-2008, 04:35 AM
Ok I can now submit the form by apending url variables, but I still need to get the selected value from the list and append this to the hidden field for transferring.

Any idea on how to do this. I tried doing this,

<select name="tool_list" ONCHANGE="update();">

With the update function like this,

function update() {
document.popupForm.tool_id.value = gettoolid(document.popupForm.tool_id);
}

The idea is to update the value of the tool_id field in the popup window with the selected id from the drop down list. But its not working!

Agent009
01-29-2008, 11:22 AM
Nevermind, solved the issue.