Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help a beginner with Form refresh

Status
Not open for further replies.

MadGeni

Technical User
Dec 13, 2002
19
GB
Hi there,

I've had a good look around, and can't see a solution to this (or quite possibly, there is a solution, just not one i understand!).
I'm a novice in ASP, so apologies in advance if this is a stupid question :)

I have a form calling another asp page, with a drop down box and two radio buttons. The drop down list is created via a SQL query, and the radio buttons are used on the following page.
What i'd like to do is change the SQL query, dependant on the radio button chosen. And this is where i have a mental blank.
The code I currently have is:
<form action = "setmaint.asp" method = post>
<%
**SQL CONNECTION BIT**

SQLstr = "SQL String goes here"
rs.open SQLstr, conn

If RS.EOF then
Response.write "<left>There are no records in the table"
Respose.write "<br>please check back later</left>"
Response.end
Else
%>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <select size="1" name="ServerName">
<option>-Select One-</option>
<%
DO WHILE NOT RS.EOF
%>
<option value="<%Response.Write RS("Object_Name")%>"><%Response.Write RS("Object_Name")%></option>
<%
Rs.MoveNext
Loop
End If
%>
</select>
<br>
&nbsp&nbsp&nbsp&nbsp&nbsp
<input type="radio" name="cont" value="yes" checked=yes> Set Maintenance(suspends jobs)
<input type="radio" name="cont" value="no" checked=yes> Remove Maintenance
<input type="submit" value="continue"
</td>
<%

I tried :
if Request.Form ("cont") = "yes" then
SQLstr = "SQLStr1"
Else
SQLstr = "SQLStr2"

at the top, but i think that's fundamentally flawed, as the ASP has already run? So i'm after a way of refreshing/running the form, after a radio button is selected..

Hope that makes sense, hope i've not missed a FAQ/thread explaining exactly how to do this!

 
well you can't have both radio buttons checked and the syntax is wrong anyway (just checked for HTML 4 checked="checked" for XHTML)

Code:
<input type="radio" name="cont" value="yes" checked=yes> Set Maintenance(suspends jobs)
<input type="radio" name="cont" value="no" checked=yes> Remove Maintenance

change this to
Code:
<input type="radio" name="cont" value="set"> Set Maintenance(suspends jobs)
<input type="radio" name="cont" value="remove"> Remove Maintenance

and use
Code:
dim Maint
Maint = lcase(Request.Form ("cont"))
select case Maint
    case "set"
         SQLstr = "SQLStr1"
    case "remove"
         SQLstr = "SQLStr2" 
    case else
         ' whichever you want as default
end select

this of course will only happen when the form is refreshed or submitted.




Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems
 
Chris,

thanks for the tips, and i appreciate the syntax correction :)

However, the fundamental problem is the form refresh, could someone enlighten me how i refresh the form upon selection of either (syntactically correct) radio button


The help is much appreciated.
 
head code

Code:
<script type="text/javascript">
function refresh()
{
location.reload()
}
</script>

form code
Code:
<form>
<input type="radio" name="radbutt" value="Refresh" onclick="refresh()">1
<input type="radio" name="radbutt" value="Refresh" onclick="refresh()">2

</form>

be very aware this will cause refresh instantly and your user may have clicked the wrong button! You can use onMouseUp="refresh()" so the mouse has to be clicked and released while the object has focus.



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems
 

I think that works too well Chris :)

the page refreshes, but it won't allow me to select a radio button, so presumably isn't letting me select a SQL query..

I'll have a look around, is it possible that onchange will work?
 
whatever you do with javascript jumps on a radio button will have the same problem. the only way that will work correctly is radio buttons then a submit button.

that's the way your users would more than likely expect to see it so there is no problem there. select an option click on a button to confirm.

the code I posted as an example was for a refresh not a form submit btw.




Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top