Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript syntax 2

Status
Not open for further replies.

JazzLeg

Programmer
Aug 22, 2002
63
GB
Hi,
Sorry more probs with my form validation. Here is a bit of my validation code and it doesn't work at the moment. I think the problem is trying access form fields from the function when only the button value is passed in.

It is important that this function is called by onclick of a button rather then onsubmit in the form tag.

Thge form name and id is 'myform'.

i think it's just syntax tho....

Code:
function mysubmitfunction(objButton) {
 var oktosubmit = true;
 // do some client checking here if all the form elements contain valid data.
 // a form element can be addressed like this:
 // eval('myform.myelement').value
 // if you cannot submit because some data in the form is not valid
 // you have to set the oktosubmit to false
 
 if (objButton.name=="update_but") { 
	if ('myform.update').value == "" {
		alert("Please select an entry to update.");
		oktosubmit = false;
     }
  }
 
 if (objButton.name=="delete_but") { 
	if ('myform.delete').value == "" {
		alert("Please select an entry to delete.");
		oktosubmit = false;
     }
  }

If 'oktosubmit' is true then further code is executed if not then the function returns false.

Thanks
 
try this
if (objButton.name=="update_but") {
if (myform.update.value == "") {
alert("Please select an entry to update.");
oktosubmit = false;
}
}
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
i'm afraid the problem's not resolved...

i just want to check a checkbox field 'delete' and a radio button field 'update'. It doesn't seem to having it tho.
 
i'm afraid the problem's not resolved...

i just want to check a checkbox field 'delete' and a radio button field 'update' to make sure they are not empty when the associated button is clicked. It doesn't seem to be having it tho.
 
then you need to be checking that condition like this
document.formname.checkboxname.checked = false ;

radio button validation looks like this
if (!document.formname.radiobuttonname[0].checked)
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
like this
if (objButton.name=="update_but") {
if (!myform.update.checked) {
//if checkbox is NOT checked
alert("Please select an entry to update.");
oktosubmit = false;
}
}

if (objButton.name=="delete_but") {
if (!myform.delete[0].checked) {
//if radio button one is NOT checked
//to check radio button two do
//&& if (!myform.delete[1].checked)
alert("Please select an entry to delete.");
oktosubmit = false;
}
} A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
how about having a global form validation function and using :

<form onsubmit=&quot;return formIsValid(this)&quot;>

when you click the submit button to verify that all is fine? Gary Haran
 
I agree with xutopia, it's more efficient and much easier for debugging and coding purposes. A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top