Urgent! Web Form validation with 3 subforms

Hi…I posted this case yesterday and I hope to get help to make my code work!

https://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/2c54ac081e628a108525725e002fcdf2?OpenDocument

Here is my code;

In JSHeader I wrote this…

function validate() {

var form = document.forms[ 0 ];



if ( form[ "orderernamn" ].value == "" || 

     form[ "contactname" ].value == "" )

{

	alert( "Please enter all mandatory fields." );

	return;

}

}

function getSelectedRadio(buttonGroup) {

// returns the array number of the selected radio button or -1 if no button is selected

for (var i=0; i<buttonGroup.length; i++) {

if (buttonGroup[i].checked) {

return i

}

}

return -1

}

function getSelectedRadioValue(buttonGroup) {

// returns the value of the selected radio button or “” if no button is selected

var i = getSelectedRadio(buttonGroup)

if (i == -1) {

return “”;

} else {

return buttonGroup[i].value;

}

}

if((getSelectedRadioValue(document.forms(0).service)==“New”) && (document.forms(0).upplName.value==“”)){

alert(“Vänligen fyll i Applikationsnamn”);

document.forms(0).applName.focus();

}

if((getSelectedRadioValue(document.forms(0).service)==“upp”) && (document.forms(0).upplName_upp.value==“”)){

alert(“Vänligen fyll i Applikationsnamn”);

document.forms(0).upplName_upp.focus();

}

if((getSelectedRadioValue(document.forms(0).service)==“other”) && (document.forms(0).other_label.value==“”)){

alert(“Vänligen fyll i Applikationsnamn”);

document.forms(0).other_labet.focus();

}

form.submit();

// end code

And “On Submit”

validate()

OBS! A subform opened depending on which “service” u choose.

I appreciate your help and suggestions…

regards,

Rebecka

Subject: Urgent!! Web Form validation with 3 subforms

JavaScript can be confusing when you first get started, but hang in there :slight_smile:

To help you debug try to put alert(‘something’) inside your code. Then you know that if the box appears, at least your code works so far. Alert also works with objects, so you can check if an object exists or is null to test if fields are present on the form or not. alert(typeof(form.someField)) should give you either object, or null…

I see that your getSelectedRadioValue() function returns the value of the object, and unless the radio button have an alias value, i suspect the value = ``. You can use text instead of value in this case.

Also, all your code needs to be inside the validate function (except the getSelected… functions of course)

function validate() {

var form = document.forms[ 0 ];



if ( form[ "orderernamn" ].value == "" || form[ "contactname" ].value == "" )

{

	alert( "Please enter all mandatory fields." );

	return;

}



if((getSelectedRadioValue(document.forms(0).service)=="New") && (document.forms(0).upplName.value=="")){

	alert("Vänligen fyll i Applikationsnamn");

	document.forms(0).applName.focus();

	return;

}



if((getSelectedRadioValue(document.forms(0).service)=="upp") && (document.forms(0).upplName_upp.value=="")){

	alert("Vänligen fyll i Applikationsnamn");

	document.forms(0).upplName_upp.focus();

	return;

}



if((getSelectedRadioValue(document.forms(0).service)=="other") && (document.forms(0).other_label.value=="")){

	alert("Vänligen fyll i Applikationsnamn");

	document.forms(0).other_labet.focus();

	return;

}

form.submit();

}

function getSelectedRadio(buttonGroup) {

// returns the array number of the selected radio button or -1 if no button is selected

for (var i=0; i<buttonGroup.length; i++) {

	if (buttonGroup[i].checked) {

		return i

	}

}

return -1

}

function getSelectedRadioValue(buttonGroup) {

// returns the value of the selected radio button or "" if no button is selected

var i = getSelectedRadio(buttonGroup)

if (i == -1) {

	return "";

} else {

	return buttonGroup[i].value;

}

}

Bjorn

Subject: Urgent!! Not solved!!Web Form validation with 3 subforms

It didn’t work, there is something missing and I can’t figure it out… :((I get the first alert “enter all mandatory” working when the document is refreshing but not when I press the “Submit” button…

My “Submit” button is Notes button Not JavaScript button, is that causing the problem?

Plaese help!!

//R

On JSHeader

// start code

function validate() {

var form = document.forms[ 0 ];

{

if ( form[ “orderernamn” ].value == “” ||

form[ “contactname” ].value == “” )

{

alert( “Please enter all mandatory fields!” );

return;

}

if((getSelectedRadioValue(document.forms(0).service)==“New”) && (document.forms(0).upplName.value==“”)){

alert(“Please enter Applications name”);

return;

document.forms(0).applName.focus();

}

if((getSelectedRadioValue(document.forms(0).service)==“upp”) && (document.forms(0).upplName_upp.value==“”)){

alert(“Please enter Applications name”);

return;

document.forms(0).upplName_upp.focus();

}

if((getSelectedRadioValue(document.forms(0).service)==“other”) && (document.forms(0).other_label.value==“”)){

alert(“Please enter Applications name”);

return;

document.forms(0).other_labet.focus();

return;

}

form.submit();

}

}

function getSelectedRadio(buttonGroup) {

// returns the array number of the selected radio button or -1 if no button is selected

for (var i=0; i<buttonGroup.length; i++) {

if (buttonGroup[i].checked) {

return i

}

}

return -1

}

function getSelectedRadioValue(buttonGroup) {

// returns the value of the selected radio button or “” if no button is selected

var i = getSelectedRadio(buttonGroup)

if (i == -1) {

return “”;

} else {

return buttonGroup[i].value;

}

}

//end code