[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Switch the 'action' field in an HTML form dynamically

Posted on 2013-01-24
4
Medium Priority
?
413 Views
Last Modified: 2013-01-24
I am trying to change the  <form action..... on a form based on the value of a textbox. The textbox on the form is txtBreed, the form is called myForm.  Here is the script.

function OnSubmitForm(){
	if(document.txtBreed == "Beagle")
	{
	document.myForm.action ="result_beagle.php";
	}
	else  if
	(document.txtBreed == "Hound")
	{ document.myForm.action ="result_hound.php";
	}
	return true;
	}

Open in new window


<form name="myForm" onsubmit="return OnSubmitForm();">
<input type="submit" value="submit" name="submit">
</form>

Open in new window


For whatever reason its not setting any form at all, when I hit submit the current page reloads.
0
Comment
Question by:DS928
  • 3
4 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 2000 total points
ID: 38815679
it should be

function OnSubmitForm(){
      if(document.txtBreed.value == "Beagle")
      {
      document.myForm.action ="result_beagle.php";
      }
      else  if
      (document.txtBreed.value == "Hound")
      { document.myForm.action ="result_hound.php";
      }
      return true;
      }
0
 

Author Comment

by:DS928
ID: 38815712
Thank you.  The same thing happens.  The current page reloads.
0
 

Author Comment

by:DS928
ID: 38815765
This worked.
function OnSubmitForm(){
      if(document.myForm,txtBreed.value == "Beagle")
      {
      document.myForm.action ="result_beagle.php";
      }
      else  if
      (document.myForm.txtBreed.value == "Hound")
      { document.myForm.action ="result_hound.php";
      }
      return true;
      } 

Open in new window

added the form name in front of the text box name.
Thank you, so much!
0
 

Author Closing Comment

by:DS928
ID: 38815768
Pointed me in the right direct, just required one tweak.  Thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question