Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Javascript help

Featured Replies

I have a coursework, it not online so don't ask for a link.

 

But anyway, I have a created a validation script and it works perfectly, until the user inputs something that doesn't validate once the script runs through and brings up the warning messages the submit button no longer works. Is there any good fixes for this? Also, If you wouldn't mind giving a small explanation that would be ace!

 

I have posted the javascript below...

 

// JavaScript Document
addLoadListener(pageSetUp);

function pageSetUp(){

var button = document.getElementById('submitbutton');
button.onclick = validateForm;
}

function validateForm()
{

if(""==document.forms.join.username.value)
{
	var uname = document.getElementById('uname');
	uname.innerHTML='Please enter a username';
	return false;
} else

{
	lengthRestriction('fname', 6, 18);	
	return false;
}

if(""==document.forms.join.name.value)
{
	var name = document.getElementById('name');
	name.innerHTML='Please enter a name';
	return false;
}

if(""==document.forms.join.day.value)
{
	var Bdate = document.getElementById('Bdate');
	Bdate.innerHTML='Please Enter a valid Birth date';
	return false;
}	
	if(""==document.forms.join.postcode.value)
{
	var Pcode = document.getElementById('Pcode');
	Pcode.innerHTML='Please enter a valid post code';
	return false;
}


}

function lengthRestriction(elem, mini, maxi){

	if(elem.length >= mini && elem.length <= maxi){
		return true;
	}else{
		var uname = document.getElementById('uname');
		uname.innerHTML='Your Username must be between 6 and 12 characters';
		return false;
	}
}

function validateForm()
{

if(""==document.forms.join.username.value)
{
	var uname = document.getElementById('uname');
	uname.innerHTML='Please enter a username';
	return false;
} else

{
	lengthRestriction('fname', 6, 18);	
	return false;
}

if(""==document.forms.join.name.value)
{
	var name = document.getElementById('name');
	name.innerHTML='Please enter a name';
	return false;
}

if(""==document.forms.join.day.value)
{
	var Bdate = document.getElementById('Bdate');
	Bdate.innerHTML='Please Enter a valid Birth date';
	return false;
}	
	if(""==document.forms.join.postcode.value)
{
	var Pcode = document.getElementById('Pcode');
	Pcode.innerHTML='Please enter a valid post code';
	return false;
}
return true;

}

 

I suppose it will now work with the injected return true. Why? I have no idea :)

  • Author

Cool, Thanks its working. But now I have another problem haha... I will post here if i cannot fix it myself lol

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.