Jump to content

Radio button


Akasha

Recommended Posts

Hello I have a form with 3 radiobuttons.Depending on which radio is selected , they will be redirected to a pagebut it doesn't matter which button i click all 3 are going to the same page (add_project) what am i doing wrong? here is the code of my form

    <p class="gen"><b>What would you like to ...</b></p>            <form name='form' method='post'>   <input type="radio" name="choice" value="Add" onclick="goto()"/> add a project?   <input type="radio" name="choice" value="Edit" onclick="goto()"/> edit a project you have added?   <input type="radio" name="choice" value="Delete" onclick="goto()"/> delete a project you have added?</form>

here is the code of my javascriptfunction

function goto(){  for (i=0;i<document.forms[0].elements.length;i++) {   if (document.forms[0].elements[i].checked)  {    if (document.forms[0].elements[i].value = "Add")      location.href = "add_project.asp"    else  if (document.forms[0].elements[i].value = "Edit")      location.href = "edit_project.asp"    else  if (document.forms[0].elements[i].value = "Delete")      location.href = "delete_project.asp"   } } }

Link to comment
Share on other sites

There is no need for a function to do what you want, just put an onclick on the radio button then a new window.location.

<p class="gen"><b>What would you like to ...</b></p>            <form name='form' method='post'>  <input type="radio" name="choice" value="Add" onclick="window.location='add_project.asp'"/> add a project?  <input type="radio" name="choice" value="Edit" onclick="window.location='edit_project.asp'"/> edit a project you have added?  <input type="radio" name="choice" value="Delete" onclick="window.location='delete_project.asp'"/> delete a project you have added?</form>

If i have misunderstood then let me know. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...