Jump to content

How do I switch a form action with a radio button?


Recommended Posts

Hello phpfreak community,

 

The issue I am having will probably be something very easy for most of you.

My goal is to be able to have multiple radio buttons which when checked will determine which form auction to choose.

As you can see in my code I currently do not have any radio buttons at the moment because each attempt I have failed miserably.

 

<form action="/searching/index.php" method="POST">

<input type="text" name="search" class="searchbar"/>
<input type="image" src="search.jpg" alt="Submit details" class="switch"/>

</form>

Below is the website I am trying to add this too.

 

www.searchpopularthings.com

 

Thanks for your help guys.

Link to comment
Share on other sites

After too many hours of research online I found out the solution, in case anyone else needs help on this use this code below.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function usePage(frm,nm){
for (var i_tem = 0, bobs=frm.elements; i_tem < bobs.length; i_tem++)
if(bobs[i_tem].name==nm&&bobs[i_tem].checked)
frm.action=bobs[i_tem].value;
}
</script>
</head>
<body>
<div>
<form action="#" method="post" onsubmit="usePage(this, 'bob');">
<input type="radio" name="bob" value="regtku1.htm">
<input type="radio" name="bob" value="regtku2.htm">
<input type="radio" name="bob" value="regtku3.htm">
<input type="submit" value="Go">
</form>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.