Changing QueryString
I would like to have the action in a form's properties change dynamically depending on what's clicked on the page. The page will have 3 checkboxes. When one is clicked I would like the action to change from GoTo.asp to GoTo.asp?Action=1 (substituting 1 for the value of each action). I'm assuming a variable could be set as ..?Action=(ActionID) or something like that and then ActionID would change depending on what's chosen.
Does anyone understand what I'm trying to get at? I am sorry if it's confusing. I'm not really good at explaining it.
Thanks for any help.
detox posted this at 02:01 — 31st July 2001.
They have: 571 posts
Joined: Feb 2001
you are on the right track..
What you want is to end up with something like this, you can either use a case statement or a series of if then elses.
I also changed the checkbox to a radio box, better if you only want 1 choice off the form.
NOTE this is only a very quick example! but it works. Also it isnt PHP but I hate putting code on these pages
<?php
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<% dim check, form
check = request.querystring(\"check\")
form = request.querystring(\"form\")
?>
<?php
If form = \"\" then
?>
<?php
Else
?>
<?php
' response.write(\"you checked box number \" & check)
?>
<?php
Select Case check
Case \"1\"
?>
This is what happens when you click on Radio button 1
<?php
Case \"2\"
?>
This is what happens when you click on Radio button 2
<?php
Case \"3\"
?>
Surprise, Surprise, This is what you get when you click on Radio button 3
<?php
Case Else
End Select
?>
<?php
End If
?>
?>
artsapimp posted this at 14:32 — 31st July 2001.
They have: 330 posts
Joined: Apr 2000
Thank you, that will work but is a little different than what I was looking for. Here's a better example.
(also not PHP but I'm following your lead)
<?php
<form action=\"GoTo.asp?Action=1\" method=\"Post\" name=\"GoToForm\">
?>
Instead of making the Action=1 static in this Form Action is there a way to make it change using javascript immediately when a radio button is clicked?
IE-
<?php
<input type=\"radio\" name=\"Action\" value=\"1\">Action 1 <!-- Action changes to 1 -->
<input type=\"radio\" name=\"Action\" value=\"2\">Action 2 <!-- Action changes to 2 -->
<input type=\"radio\" name=\"Action\" value=\"3\">Action 3 <!-- Action changes to 3 -->
?>
Do you see what I'm looking for? I know I could send it through the form and receive it using request.form but this would be more consistant with the project I'm building.
Here's an idea of how it could be done if ASP would work immediately without sending a form.
<?php
<%
Dim varAction
?>
?>
Do you see what I'm looking for?
Free Math Test
Fun Math Games
Adrian J. Moreno posted this at 15:12 — 31st July 2001.
They have: 19 posts
Joined: Jul 2001
What you want to do is change the value of the form object "action". You do this with JavaScript, not ASP, CF, PHP, etc.. And it's best to use radio buttons for this instead of checkboxes as radio buttons with the same name ensure that only one choice can be made.
Just change the values of the radio buttons to the page & querystring you want to pass.
<html>
<head>
<title>Javascript - Switch "Action" page</title>
<script language="JavaScript" type="text/javascript">
<!--
function changeAction(x) {
document.changeMe.action = x;
}
//-->
</script>
</head>
<body>
<form name="changeMe" action="" method="post">
<input type="radio" name="myAction" value="ActionA.htm" onClick="changeAction(this.value)">Action A<br>
<input type="radio" name="myAction" value="ActionB.htm" onClick="changeAction(this.value)">Action B<br>
<input type="radio" name="myAction" value="ActionC.htm" onClick="changeAction(this.value)">Action C<br>
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
You can even ditch the Javascript function call completely and go with this:
<html>
<head>
<title>Javascript - Switch "Action" page - version 2</title>
</head>
<body>
<form name="changeMe" action="" method="post">
<input type="radio" name="myAction" value="ActionA.htm" onClick="document.changeMe.action = this.value">Action A<br>
<input type="radio" name="myAction" value="ActionB.htm" onClick="document.changeMe.action = this.value">Action B<br>
<input type="radio" name="myAction" value="ActionC.htm" onClick="document.changeMe.action = this.value">Action C<br>
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
If you put a default value in the action attribute of the tag, you'll catch when someone fails to choose a radio button. If you don't want to add a default action page in the form tag, you can choose a radio button to be checked by default.
<input type="radio" name="myAction" value="ActionA.htm" onClick="document.changeMe.action = this.value" checked>Action A
artsapimp posted this at 15:21 — 31st July 2001.
They have: 330 posts
Joined: Apr 2000
Thank you thank you thank you. That was exactly what I was looking for.
artsapimp posted this at 15:57 — 31st July 2001.
They have: 330 posts
Joined: Apr 2000
I am not getting an error, but nothing happens. I view the source and it doesn't seem to be changing the value of the Form's Action. Here's some of my code. Am I doing something wrong?
<?php
<form action=\"SetSessions.asp\" method=\"Post\" name=\"StepList\"><table width=\"350\" cellpadding=\"0\" cellspacing=\"0\" class=\"Table\">
<tr>
<td colspan=\"2\" class=\"SmallLine\" height=\"2\"> </td>
</tr>
<tr>
<td colspan=\"2\" class=\"SmHeader\">Customer's Issue</td>
</tr>
<tr>
<td colspan=\"2\" class=\"SmallLine\" height=\"2\"> </td>
</tr>
<% If StepFrom = 0 Then
?>
<?php
Do until rst.EOF
?>
<?php
= rst(\"Step\")
?>
?>
Thank you for your help.
Free Math Test
Fun Math Games
artsapimp posted this at 16:06 — 31st July 2001.
They have: 330 posts
Joined: Apr 2000
Is it because of the tables?
Adrian J. Moreno posted this at 16:15 — 31st July 2001.
They have: 19 posts
Joined: Jul 2001
Ok, you have
Which is way too much.
Break down the radio button:
this.value MEANS the value of the current radio button - the one you clicked on, so you do not replace that with ASP code.
What is the final output when you've rendered Value="
<?php
= rst("To")
?>
It should be something to the effect of
value="SetSessions.asp?Step=1&Value=2"
And you won't see the changed action page reference in the source code, you'll only see the default action page that you wrote in. The JavaScript tells the browser to change to a different action page - it doesn't write it out.
artsapimp posted this at 16:22 — 31st July 2001.
They have: 330 posts
Joined: Apr 2000
The rst("To") is a numeric value. It is not a URL.
It works perfectly now. I just didn't test it before because the action didn't look like it was changing.
Thank you again for your help.
Free Math Test
Fun Math Games
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.