iT邦幫忙

0

請問怎麼避免value被刷新

不好意思 想請教各位高手
我有一隻上傳程式uploadfile.asp, 裡面會重新導向到主頁面adadd.asp
Response.Write "parent.location='../../?Action=adadd';"

請問我要怎麼避免主頁面已經填好的value被刷掉例如 input, select, 等欄位
例如asadd.asp:

<td>
        <select name="siteclassid" id="siteclassid" style="width:400px;">
          <option selected value="">請選擇分類</option>
          <%
            
            <option value="<%=Rs2("ID")%>"><%=Rs2("SiteClassName")%></option>
            <%
          %>
        </select>
      </td>
ccutmis iT邦高手 2 級 ‧ 2021-04-15 12:11:07 檢舉
或者在上傳的時候把值存為 session 變數 重導回上傳頁面時再讀取 session 變數帶到對應的欄位
開了上傳也要把目前的值一起拋出去,然後用隱藏欄位紀錄,等拋回來之後,會自然而然用拋之前的值取代目前的值,這是懶人法,給樓主參考
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
1
純真的人
iT邦大師 1 級 ‧ 2021-04-15 11:48:08
最佳解答

你要把值帶過去~

Response.Write "parent.location='../../?Action=adadd';"

改成

Response.Write "parent.location='../../?Action=adadd&siteclassid=1';"

然後在asadd.asp接值紀錄

siteclassid = request("siteclassid")
if siteclassid = "" then
siteclassid = 0
end if

然後在欄位把值帶入

<td>
        <select name="siteclassid" id="siteclassid" style="width:400px;">
          <option selected value="">請選擇分類</option>
          <%
            
            <option value="<%=Rs2("ID")%>" <%if siteclassid = Rs2("ID") then%>selected<%end if%>><%=Rs2("SiteClassName")%></option>
            <%
          %>
        </select>
      </td>
看更多先前的回應...收起先前的回應...
小火車 iT邦新手 4 級 ‧ 2021-04-15 15:19:41 檢舉

大大 抱歉我敘述的不清楚
asadd.asp 主頁面有一個 上傳圖片 的功能

<td colspan='6'><iframe style="top:2px" ID="UploadFiles2" src="../../include/uploadfile.asp?UserType=aduser&Site=imglist" frameborder=0 scrolling=no width="400" height="30" allowtransparency="true"></iframe></td>

點上傳功能會到uploadfile.asp 執行上傳相關作業

 If UserType="aduser" Then
 If Site="adadd" Then
 Response.Write "parent.document.form_adadd.ad_2.value='" & RootPath & "upload/"&FileName_2 & "';" & vbcrlf
Response.Write "alert('上传成功!');" & VbCrlf
Response.Write "history.go(-1);" & vbCrlf
ElseIf Site="imglist" Then
Response.Write"parent.location='../"&AdUserManagePath&"/?Action=adadd';" & vbcrlf
Response.Write "alert('上传成功!');" & VbCrlf
		End If
	 End If

請問包在iframe裡面會影響傳值嗎?

因為在iframe裡面的這句 parent.location 把你原本那頁轉址掉了@@..
所以在uploadfile.asp上傳前...
在uploadfile.asp裡面寫JS Code抓parent紀錄(asadd.asp)的相關值~
然後uploadfile.asp送出上傳後~連帶把值帶過去給

Response.Write"parent.location='../"&AdUserManagePath&"/?Action=adadd&xxx&xxx&xx';"

然後你被轉址的asadd.asp就會接到上傳頁的傳值了~
你在把接來的傳值重新設定到相關欄位的預設值裡面~

我推測應該是這樣的@@...

小火車 iT邦新手 4 級 ‧ 2021-04-15 16:16:07 檢舉

感謝各位大大的解答 這classic asp我真的不懂

他其實跟php是一樣的架構~
只是比.net架構簡單~隨意定義~

小火車 iT邦新手 4 級 ‧ 2021-04-15 23:10:14 檢舉

大大能在請問一個問題嗎?
uploadfile.asp裡面寫JS Code抓parent紀錄(asadd.asp)的相關值
請問這段JS Code怎麼寫... 能教教我嗎?

這個就要看asadd.asp相關欄位的原始碼了= =a
很麻煩的寫Js取值記錄到uploadfile.asp的表單欄位..

小火車 iT邦新手 4 級 ‧ 2021-04-15 23:54:16 檢舉

還是說大大有沒有個範例 給我一個hint 我去研究研究 真的不好意思麻煩了

沒有呢~這個就真的~見招拆招了..
要不然~就把他本頁轉址刪除~直接無視@@~
只顯示上傳成功~

刪除這行~

Response.Write"parent.location='../"&AdUserManagePath&"/?Action=adadd';" & vbcrlf
小火車 iT邦新手 4 級 ‧ 2021-04-16 00:08:50 檢舉

好 感謝你 我在研究研究 非常感謝!!

1
海綿寶寶
iT邦大神 1 級 ‧ 2021-04-15 11:49:44

假設之前選的分類的變數叫 selectedClass
要改兩個地方

1.asadd.asp
<option value="<%=Rs2("ID")%>"><%=Rs2("SiteClassName")%></option>
改成<option value="<%=Rs2("ID") @((selectedClass == Rs2("ID")) ? "selected" : "")%>"><%=Rs2("SiteClassName")%></option>
另外
在最前面加一列selectedClass = request.querystring("selcls")

2.Response.Write "parent.location='../../?Action=adadd';"
Response.Write "parent.location='../../?Action=adadd';"
改成Response.Write "parent.location='../../?Action=adadd&selcls=ID03';"
注意:那個 ID03 要用你當時選擇分類的 ID,不是直接寫 ID03

我要發表回答

立即登入回答