SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: action variable
-
Jan 11, 2002, 14:43 #1
- Join Date
- Sep 2001
- Location
- PF / RS / BR
- Posts
- 207
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
action variable
How do I set the ACTION variable of a form in javascript, i.e. I have some radios. If a user chooses radio one, the action is set to a script (script1.php), if he chooses radio two, action is set to another script (script2.php) and so on.
Some help, please?php? mysql? apache? That's it.
-
Jan 11, 2002, 14:49 #2
- Join Date
- Mar 2001
- Location
- the windy city
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Untested, but I have an idea:
instead of writing your <form> tag with HTMl write it with javascript:
<script language="javascript"><!--
document.write("<form name='frm' method='post' action='" + document.frm.radio_name.value + "'>")
//-->
</script>
Please let me know if it had worked.
-
Jan 11, 2002, 15:04 #3
- Join Date
- Mar 2001
- Location
- the windy city
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not sure the first example will work since you are writing a <form> tag before the frm is read and JS might get confused by the "radio_name.value" thing. So I have thought of another idea.
write your form in html as usual, but don't specify the action. Then, instead of <input type="submit"> have <input type="botton" value="submit" onClick="subm()">
then have
function subm() {
document.form_name.action = document.form_name.radio_name.value
document.form_name.submit()
}
HTH
-
Jan 11, 2002, 16:34 #4
- Join Date
- Mar 2001
- Location
- the windy city
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not sure the first example will work since you are writing a <form> tag before the frm is read and JS might get confused by the "radio_name.value" thing. So I have thought of another idea.
write your form in html as usual, but don't specify the action. Then, instead of <input type="submit"> have <input type="botton" value="submit" onClick="subm()">
then have
function subm() {
document.form_name.action = document.form_name.radio_name.value
document.form_name.submit()
}
HTH
-
Jan 11, 2002, 18:47 #5
Agreed, you want to set the form.action property. I would do it differently though (and this is untested) by not assigning an action to the form in the form tag and using event handlers to set the action.
Code:<input type="radio" name="blah" value="etc1" onClick="document.formName.action='first_action_URL'"> <input type="radio" name="blah" value="etc2" onClick="document.formName.action='second_action_URL'">
-
Jan 14, 2002, 06:30 #6
- Join Date
- Sep 2001
- Location
- PF / RS / BR
- Posts
- 207
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have used this function, but it didn't work. I'm a newbie to javascript, so I'm asking for help again.
PHP Code:<script language="javascript">
<!--
function subm()
{
document.my_form.METHOD = "POST";
document.my_form.action = document.form_name.radios.value;
document.my_form.submit();
}
// end hide -->
</script>
...
<form name="my_form">
<input type="radio" name="radios" value="script1.php">script1<br><br>
<input type="radio" name="radios" value="script2.php">script2<br><br>
<input type="button" name="submit" value="submit" onClick="subm()">
</form>
php? mysql? apache? That's it.
-
Jan 14, 2002, 10:50 #7
- Join Date
- Mar 2001
- Location
- the windy city
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
rwar,
at the first glance I have spotted the following:
document.my_form.action*=*document.form_name.radios.value
should actually be
document.my_form.action*=*document.my_form.radios.value
since your form's name is "my_form"
-
Jan 14, 2002, 11:29 #8
- Join Date
- Sep 2001
- Location
- PF / RS / BR
- Posts
- 207
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, valeria_vi. But I'm not understanding the point you want I change the script.
Could you use the script I write and change it?php? mysql? apache? That's it.
-
Jan 14, 2002, 11:31 #9
- Join Date
- Sep 2001
- Location
- PF / RS / BR
- Posts
- 207
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The bottom bar (Internet Explorer) shows
JavaScript error: Type 'javascript' into location for details.php? mysql? apache? That's it.
-
Jan 14, 2002, 12:14 #10
- Join Date
- Mar 2001
- Location
- the windy city
- Posts
- 281
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have an error in this line:
document.my_form.submit();
there should be no () after submit i.e. the line should look like this:
document.my_form.submit;
also, i wouls keep document.my_form.METHOD to be all lower-case.
my final code looked like this:
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<script language="javascript"><!--
function subm() {
document.my_form.method = "post"
document.my_form.action = document.my_form.radios.value
document.my_form.submit
}
//-->
</script>
</HEAD>
<BODY>
<form name="my_form">
<input type="radio" name="radios" value="script1.php">script1<br><br>
<input type="radio" name="radios" value="script2.php">script2<br><br>
<input type="button" name="submit" value="submit" onClick="subm()">
</form>
</BODY>
</HTML>
and it gave me no errors
Bookmarks