7 Replies - 2026 Views - Last Post: 22 December 2008 - 07:08 AM

#1 Mouse86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-June 08

Calling external functions?

Posted 20 December 2008 - 01:51 AM

//I used the code//

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<body>
<head>
<link rel="stylesheet" type="text/css" href="css.css" />
<script type='text/javascript' src='../notepad++/verify.html'></script>
</head>
<form action="../notepad++/mainpage.html" onsubmit="validateForm()" method="post">
<table align='left'>
<tr><td align='right'>
Username: <input type="text" name="users" />
</td></tr>
<tr><td align='right'>
Password: <input type="password" name="passes" />
</td></tr>
<tr><td align='right'>
Confirm Password: <input type="password" name="confirmpasses" />
</td></tr>
<tr><td align='right'>
Email: <input type="text" name="emails" />
</td></tr>
<tr><td align='right'>
Confirm Email: <input type="text" name="confirmemails" />
</td></tr>
<tr><td align='center'>
<input type="submit" value="SUBMIT" class="button" />
</td></tr>
</table>
</form>
</body>
</html>

/*But it doesn't seem to tranfer the information in the form to my external JS page ???*/





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<style type="text/javascript">
function validateEmail(emails, confirmemails, alerttxt)
{
	with(emails)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2)
		{
			alert("Incorrect Email");
			return false;
		}
		else
		{
			if (emails===confirmrmails)
			{
				return true;
			}
			else
			{
				alert("Emails do not match, please try again");
				return false;
			}
		}
	}
}
function validatePass(passes, confirmpasses, alerttxt)
{
	with(passes)
	{
		if (value=null||value="")
		{
			alert("Password is not acceptable");
			return false;
		}
		else
		{
			if (passes===confirmpasses)
			{
				return true;
			}
			else
			{
				alert("Passwords do not match");
				return false;
			}
		}
	}
}
function validateForm(users, passes, emails)
{
	if (validatePass())
	{
		if (validateEmails())
		{
			//??underConstruction??//
		}
	}
	else
	{
		location.href="../notepad++/registration.html";
	}
}
</script>
</body>
</html>



This post has been edited by Mouse86: 20 December 2008 - 12:49 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Calling external functions?

#2 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 828
  • Joined: 25-October 08

Re: Calling external functions?

Posted 20 December 2008 - 09:19 AM

Quote

/*But it doesn't seem to tranfer the information in the form to my external JS page ???*/

I'm not sure I understand this statement. :blink:

You don't have any external JS reference.
And what does the function 'validateForm()' do? Are you getting any errors?
Was This Post Helpful? 0
  • +
  • -

#3 Mouse86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-June 08

Re: Calling external functions?

Posted 20 December 2008 - 11:55 AM

View PostJMRKER, on 20 Dec, 2008 - 08:19 AM, said:

Quote

/*But it doesn't seem to tranfer the information in the form to my external JS page ???*/

I'm not sure I understand this statement. :blink:

You don't have any external JS reference.
And what does the function 'validateForm()' do? Are you getting any errors?



I have an external JS. 'Validate form()' validates the username and password entered into a registration form. I am not getting any errors. It seems the code is just skipping passed the 'onsubmit' command because when I click submit, the page will run the 'action=' without coming up with an alertbox telling the viewer that they cannot submit a blank form (which is what validateForm is supposed to do).
Was This Post Helpful? 0
  • +
  • -

#4 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 828
  • Joined: 25-October 08

Re: Calling external functions?

Posted 20 December 2008 - 12:39 PM

You have no reference to call an external file in what you posted.
If you are calling an external file you should be using
<script type="text/javascript" src="ValidateFormFilename.js"></script>

In addition, what does this external file look like? You should post this as well as it is part of the code that you did supply in post #1. It too could contain errors that give you your current symptoms.
To test that it is being called correctly, put some alert(message) in that code where you expect it to execute with the information provided.

I am also assuming that you do have an "action=" defined in your true code.
If not I would expect just what is happening now, which is nothing.
Was This Post Helpful? 0
  • +
  • -

#5 Mouse86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-June 08

Re: Calling external functions?

Posted 21 December 2008 - 01:17 AM

View PostJMRKER, on 20 Dec, 2008 - 11:39 AM, said:

You have no reference to call an external file in what you posted.
If you are calling an external file you should be using
<script type="text/javascript" src="ValidateFormFilename.js"></script>

In addition, what does this external file look like? You should post this as well as it is part of the code that you did supply in post #1. It too could contain errors that give you your current symptoms.
To test that it is being called correctly, put some alert(message) in that code where you expect it to execute with the information provided.

I am also assuming that you do have an "action=" defined in your true code.
If not I would expect just what is happening now, which is nothing.





I tried the alert test and got nothing. The onsubmit is not calling the function for some reason, the rest of my code is posted at top, if you want to take a look.
Was This Post Helpful? 0
  • +
  • -

#6 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 828
  • Joined: 25-October 08

Re: Calling external functions?

Posted 21 December 2008 - 08:10 AM

The problem starts here:
<script type='text/javascript' src='../notepad++/verify.html'></script>


You are trying to call JS code from inside an HTML file. No Go!

Remove ALL html tags from the 'verify.html' and save as 'verify.js'
Then change your call like this:
<script type='text/javascript' src='./path/verify.js'></script>
<!-- path is only defined if it is in a different subdirectory -->


Was This Post Helpful? 0
  • +
  • -

#7 Mouse86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 24-June 08

Re: Calling external functions?

Posted 22 December 2008 - 01:51 AM

View PostJMRKER, on 21 Dec, 2008 - 07:10 AM, said:

The problem starts here:
<script type='text/javascript' src='../notepad++/verify.html'></script>


You are trying to call JS code from inside an HTML file. No Go!

Remove ALL html tags from the 'verify.html' and save as 'verify.js'
Then change your call like this:
<script type='text/javascript' src='./path/verify.js'></script>
<!-- path is only defined if it is in a different subdirectory -->



I've done so, still didn't work. I've also tried other ideas that I found on the net, like saving the file using normal text as verify.js. I think that my problem is in

<form action="../notepad++/mainpage.html" onsubmit="validateForm()" method="post">



Was This Post Helpful? 0
  • +
  • -

#8 JohnWaters  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 138
  • Joined: 28-November 08

Re: Calling external functions?

Posted 22 December 2008 - 07:08 AM

I don't think the main problem is the external JS file.
There are functions eg. function validateForm(users, passes, emails) which expect parameters.
BUT your not passing any parameters into these functions.
The best thing to do is maybe pass the form object and then use that eg.
onsubmit="validateForm(this)"

function validateForm(form)
{
   var users = form.users.value;
   var passes = form.passes.value;
   var emails = form.emails.value;
...

You should review all your code again, you still have some work to do!

This post has been edited by JohnWaters: 22 December 2008 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1