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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.