[英]Passing loop values of child window to parent window and vice versa
我有一個名為用戶名的文本框。當我雙擊該文本框時,應打開一個子窗口。在該子窗口中,使用mysql查詢的while循環顯示用戶名列表。我的問題是我雙擊它ll傳遞一個undefined值。這個問題是由於用戶名從db表中循環而來。我該如何解決? 請盡快幫助我。這里是我的代碼。
<script type="text/javascript">
function displaymessage(){
opener.document.cash_entry.sub_name.value = document.subscriber.subname.value;
self.close();
}
</script>
<form>
<?php
$sel=mysql_query("select * from add_ticket");
while($row=mysql_fetch_array($sel)) {
$subscriber=$row['subscriber'];
?>
<input type="text" name="subid" id="subid" value="<?php echo $subscriber; ?>"
ondblclick="displaymessage()" readonly="true">
<?php } ?>
</form>
您沒有為表單命名,並且給字段命名的方式與HTML代碼中的命名方式不同,並且在具有相同名稱的element上有多個元素,如果有多個元素,則將其作為數組
做這個
<script type="text/javascript">
function displaymessage(fld){
opener.document.cash_entry.sub_name.value = fld.value;
self.close();
}
</script>
<form>
<?php
$sel=mysql_query("select * from add_ticket");
while($row=mysql_fetch_array($sel)) {
$subscriber=$row['subscriber'];
?>
<input type="text" name="subname"
id="subid<?php echo $subscriber; ?>"
value="<?php echo $subscriber; ?>"
ondblclick="displaymessage(this)" readonly="true">
<?php } ?>
</form>
為什么不
<input type="button" value="<?php echo $subscriber; ?>"
onclick="displaymessage(this)" >
對於多個價值,您可以
function displaymessage(fld){
var parts = fld.value.split("|");
opener.document.cash_entry.sub_name.value = parts[0];
opener.document.cash_entry.sub_id.value = parts[1];
self.close();
}
<input type="button"
value="<?php echo $subscriber; ?>|<?php echo $subscriberID; ?>"
onclick="displaymessage(this)" >
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.