How to give individual  action url to every "radio" button  on my form submission?

Fernanditos
Fernanditos used Ask the Experts™
on
Hi

I have the attached static HTML form with radio selector. For any selection I need to redirect to different urls that I will write manually.

How can I implement this?
<form action="index.php" method="post" id="idb" name="ExploreSearchForm">
  <div class="search_dropdown open"> <a href="#" class="searchFilter right"><span class="left"><span class="icon" style="font-size:22px;">Everything</span></span></a>
    <div class="searchFilters displayNone">
      <div class="search_top"></div>
      <div class="search_options">
        <h4>Search:</h4>
        <label for="id1-id2">
          <input type="radio" checked="checked" name="search_type"  value="radio17"/>
          Everything </label>
        <label for="id1-id3">
          <input type="radio" name="search_type" value="radio18"/>
          Updates </label>
        <label for="id1-id4" class="photos">
          <input type="radio" name="search_type"  value="radio19"/>
          Photos </label>
        <div align="left">
          <input type="submit"   id="idc" value="" class="searchSubmit" title="Search" name="ExploreSearchSubmitLink"/>
        </div>
      </div>
    </div>
  </div>
</form>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Send to one page, on that page redirect as needed depending on the radio button selected.
Hi Fernanditos, you can do this by two ways.
one in PHP and other in Javascript. here is the code.

Let me know if you have any clarifications

<?php
// Redirect User to diffrent webpages
//Getting Which Radio Button selected
$selected_radio = $_POST['search_type'];
//print $selected_radio;
if($selected_radio == "radio17")
//Redirect Here
die();


?>

//here by Javascript
<script type="text/javascript>

function get_searchradio_value()
{
	for (var i=0; i < document.ExploreSearchForm.search_type.length; i++)
	{
		if (document.ExploreSearchForm.search_type[i].checked)
		{
			alert(document.ExploreSearchForm.search_type[i].value);
			//Redirect here by Javascript
			window.location = "http://www.google.com/";
		}
   }
}

</script>

<form action="index.php" method="post" id="idb" name="ExploreSearchForm">
  <div class="search_dropdown open"> <a href="#" class="searchFilter right"><span class="left"><span class="icon" style="font-size:22px;">Everything</span></span></a>
    <div class="searchFilters displayNone">
      <div class="search_top"></div>
      <div class="search_options">
        <h4>Search:</h4>
        <label for="id1-id2">
          <input type="radio" checked="checked" name="search_type"  value="radio17"/>
          Everything </label>
        <label for="id1-id3">
          <input type="radio" name="search_type" value="radio18"/>
          Updates </label>
        <label for="id1-id4" class="photos">
          <input type="radio" name="search_type"  value="radio19"/>
          Photos </label>
        <div align="left">
          <input type="button" onclick="get_searchradio_value()"  id="idc" value="" class="searchSubmit" title="Search" name="ExploreSearchSubmitLink"/>
        </div>
      </div>
    </div>
  </div>
</form>

Open in new window

leakim971Multitechnician
Top Expert 2014
Commented:
Hello Fernanditos,

Try this :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script language="javascript">
	function wheretogo() {
		var r = document.getElementsByTagName('input');
		for(var i=0;i<r.length;i++)
			if((r[i].name=='search_type')&&r[i].checked) whichone = r[i].value;
		var f = document.getElementById('idb');
		switch(whichone) {
			case "radio17" : f.action="http://www.google.com";break;
			case "radio18" : f.action="http://www.yahoo.com";break;
			case "radio19" : f.action="http://www.live.com";break;
			default: f.action="http://www.experts-exchange.com"
		}
	}
</script>
</head>

<body>
<form action="" method="post" id="idb" name="ExploreSearchForm" onsubmit="wheretogo();">
  <div class="search_dropdown open"> <a href="#" class="searchFilter right"><span class="left"><span class="icon" style="font-size:22px;">Everything</span></span></a>
    <div class="searchFilters displayNone">
      <div class="search_top"></div>
      <div class="search_options">
        <h4>Search:</h4>
        <label for="id1-id2">
          <input type="radio" checked="checked" name="search_type"  value="radio17"/>
          Everything </label>
        <label for="id1-id3">
          <input type="radio" name="search_type" value="radio18"/>
          Updates </label>
        <label for="id1-id4" class="photos">
          <input type="radio" name="search_type"  value="radio19"/>
          Photos </label>
        <div align="left">
          <input type="submit"  id="idc" value="Submit search type" class="searchSubmit" title="Search" name="ExploreSearchSubmitLink"/>
        </div>
      </div>
    </div>
  </div>
</form>
</body>
</html>

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hi, Both solutions are working nice, the second one is working but it give me an warning error: "Notice: Undefined index: search_type in C:"

Author

Commented:
Sorry, the second one is  working perfect, the first one from Patrickjjs is returning the error.

Thank you guys for the great help.
leakim971Multitechnician
Top Expert 2014

Commented:
You're welcome!
Hi Fernanditos, sorry I not tested my code. Happy you got answer.
leakim971Multitechnician
Top Expert 2014

Commented:
Thanks for the points!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial