2 Replies - 1318 Views - Last Post: 01 March 2011 - 08:30 AM

#1 Dean_Grobler   User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 390
  • Joined: 15-January 10

Send form data to diff page using javascript NOT working

Posted 01 March 2011 - 06:46 AM

hey there,

This is my file with the form in:
<html>
<head>
<title>The Form</title>
</head>
<body>
<h2>The Form:</h2>
<form id="myForm" action="error.html">
	<button id="button 1">Page one</button>
	<button id="button 2">Page two</button>
</form>
<script type="text/javascript" src="EventHandler.js"></script>
</body>
</html>



This is the javascript file that is suppose to send the form data to the right html document.
//Get the buttons
var b1 = document.getElementById("button 1");
var b2 = document.getElementById("button 2");

//Function to change the action attribute
function changeAction(url)
{
	document.getElementById("myForm").action = url;
}

//Event Handler
b1.onclick = function page1() { changeAction("PageOne.html"); };
b2.onclick = function page2() { changeAction("PageTwo.html"); };



Then the two tiny pages that are suppose to get displayed depending on the
button that was clicked:

PageOne:
<html>
<head>
</head>
<body>
<h2>Page one!</h2>
</body>
</html>



PageTwo:
<html>
<head>
</head>
<body>
<h2>Page two!</h2>
</body>
</html>



And... It's' not working, I have no idea why not, since I've made this work before and I did exactly the same thing? Please does anyone know what's up?

Is This A Good Question/Topic? 0
  • +

Replies To: Send form data to diff page using javascript NOT working

#2 Sadin56   User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Send form data to diff page using javascript NOT working

Posted 01 March 2011 - 08:19 AM

Are you sure this isnt a Javascript problem try asking this in the Javascript Forum to grab more attention.
Was This Post Helpful? 0
  • +
  • -

#3 chinchang   User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 727
  • Joined: 22-December 08

Re: Send form data to diff page using javascript NOT working

Posted 01 March 2011 - 08:30 AM

Try
<input type="submit" id="button1" />
instead of
<button>


EDIT : changed the mistake in the code.

This post has been edited by chinchang: 01 March 2011 - 08:42 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1