Click to See Complete Forum and Search --> : how to validate a php general form?
bobby_dummy_022
12-03-2003, 07:22 PM
Currently I am able to validate form fields (making sure that the user has entered some value for them), for those form elements which are generally statically, via static html.
However, some elements of the form are generated via the PHP server. How can I validate those?
Perhaps get the PHP server to generate Javascript? and generate a submit method? where the contents of the method are dependant upon the contents of the php generated form?
suggestions?
is there any javascript method which makes all form input fields to have a value? regardless of how many, and the names of each input field?
If so, I could just call that upon submittion..
Khalid Ali
12-03-2003, 07:51 PM
yes actually if you want all of the text fields to have some value,you can use something like this
var tfields = document.getELementByTagName("input");
//this will give you an array of all input elements,now go through them and enter any value in the typ="text"
var len = tfields.length;
for(var n=0;n<len;n++){
if(tfield[n].type!=null && tfield[n].type=="text"){
//set any value here
tfield[n].value="default";
}
}
bobby_dummy_022
12-03-2003, 08:23 PM
I tried that, and it does not work.
After some debugging and testing, I have worked our that the following line does not work:
var tfields = document.getElementByTagName("input");
getElementByTagName is not a core function...
after trying to find information about the "document" onject, and how it is created, and using which class? I could not find anything...
I am familiar with Java, however Javascript is new to me, and I am having trouble finding info about it.
bobby_dummy_022
12-03-2003, 11:06 PM
Khalid Ali, what exactly is that method?
why does this not work for me?
var tfields = document.getELementByTagName("input");
Pittimann
12-04-2003, 12:43 AM
Hi!
Just some typos in the code. Try this:
<script language="JavaScript" type="text/javascript">
<!--
function check(){
var tfields = document.getElementsByTagName("input");
//this will give you an array of all input elements,now go through them and enter any value in the typ="text"
var len = tfields.length;
for(var n=0;n<len;n++){
if(tfields[n].type!=null && tfields[n].type=="text"){
//set any value here
tfields[n].value="default";
}
}
}
//-->
</script>
Cheers - Pit