TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hayden Meherg
NA
35
5.9k
How to change form action attribute value based on selection
Jul 1 2019 3:34 PM
I've looked at countless examples on here and not sure what I'm doing wrong. I'm trying to change the form action based on the selected value from a dropdown menu.
Basically, the HTML looks like this:
<
form
id
=
"storetable"
autocomplete
=
"off"
action
=
""
method
=
"post"
>
<
label
>
STORE:
</
label
>
<
input
type
=
"text"
list
=
"storeID"
name
=
"store"
placeholder
=
"Choose a store..."
required
>
<
datalist
id
=
"storeID"
>
<
option
value
=
"cwb_coins"
>
Causeway Bay
</
option
>
<
option
value
=
"wc_coins"
>
Wan Chai
</
option
>
<
option
value
=
"lck_coins"
>
Lai Chi Kok
</
option
>
<
option
value
=
"tp_coins"
>
Tai Po
</
option
>
</
datalist
>
</
form
<script>
$(document).ready(
function
(){
$(
"#storeID"
).change(
function
(){
var
url = $(
this
).children(
":selected"
).text();
//get the selected option value
switch
(url)
{
case
"cwb_coins"
:
$(
"#storetable"
).attr(
'action'
,
'cwb_coin_code.php'
);
//changing action attribute of form to school.php
break
;
case
"wc_coins"
:
$(
"#storetable"
).attr(
'action'
,
'wc_coin_code.php'
);
break
;
case
"lck_coins"
:
$(
"#storetable"
).attr(
'action'
,
'lck_coin_code.php'
);
break
;
case
"tp_coins"
:
$(
"#storetable"
).attr(
'action'
,
'tp_coin_code.php'
);
break
;
default
:
$(
"#storetable"
).attr(
'action'
,
'#'
);
}
});
});
</script>
Reply
Answers (
1
)
footable add new row
Help Me in jquery