London wrote:
Thank you very much.
but
I wrote this code:
dim xy
Response.Write "<FORM>"
Response.Write "<B><TR><SELECT name=""select1"" Width=394px>"
Response.Write "<OPTION value=""1"">One</OPTION>"
Response.Write "<OPTION value=""2"">Two</OPTION>"
Response.Write "</SELECT></TR></B>"
Response.Write "</FORM>" & Chr(13)
xy=Request.Querystring("select1")
Response.Write "<P><input type=""text"" id=""text1""
name=""text1""></P>" Response.Write "<P><input type=""button""
value=""ButtonX"" onclick=""text1.value='" & xy & "';""
METHOD=""get"" id=button1 name=button1></P>"
I click the button(ButtonX),but the testbox(text1) is none.
Can you more help me
You're doing too much response.write'ing. This is very hard to follow (and,
it must be hard to write). Nevertheless, some problems do reveal themselves:
1. METHOD is an attribute of a FORM element, not an INPUT element
2. You aren't telling the form where it should be submitted - use the FORM
element's ACTION attribute
3. You aren't submitting the form - you need to
a. have a Submit input element within the FORM, or
b. have your button input element's onclick event include code to submit
the form
4. You do not seem to understand when the xy variable will be populated.
When an asp page is called on the server, all server-side code is executed
before the resulting html is sent to the client. So, in your code, when the
asp page is called, the hetml that is sent to the client browser includes
this code (which you can verify by using View Source in your browser
window):
<input type="text" id="text1" name="text1">
<input type="button" value="ButtonX"" onclick="text1.value='';"
METHOD=""get"" id=button1 name=button1>
You see? When this button is clicked, it will set the text1.value to a blank
string. And nothing else will happen.
But let's suppose that you also included code to submit the form. Assuming
you've set the ACTION attribute to submit the form to itself, when you submi
t the page after select "Two" in the dropdown, and it reloads in the client
browser, the html source of the reloaded page will look like this:
<input type="text" id="text1" name="text1">
<input type="button" value="ButtonX"" onclick="text1.value='2';"
METHOD=""get"" id=button1 name=button1>
So, the textbox will still be blank ... until you click the button. But,
when you click the button, the form will be resubmitted, so the user will
never have a chance to see the new value of the textbox.
Here is what I would do (this code has been tested - give it a try):
<%
'This page is called ASPPage6.asp
option explicit
dim xy
xy=Request.Querystring("select1")
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM action="ASPPage6.asp" method=GET id=form1 name=form1>
<SELECT id=select1 name=select1>
<OPTION value="1">One</OPTION>
<OPTION value="2">Two</OPTION>
</SELECT>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
<P>
<INPUT type="text" id=text1 name=text1 value="<%=xy%>">
</P>
</FORM>
</BODY>
</HTML>
When the page initially loads in the browser, the textbox will be blank.
When you select an option from the dropdown and click the Submit button, the
page will reload and the textbox will contain the selected value
HTH,
Bob Barrows