Hi there. I have the code below for a validating and retrieving the data from a form. However, i have tried putting the data from the form into an array in the javascript, but am not sure how to do this. Any help would be much appreciated.
<Script Language=JavaScript>
function validEntries(isForm){
isValid = false;
nButtons = document.getElementsByName('optS_Class');
for (i=0; i<nButtons.length; i++)
{
if (nButtons[i].checked == true){className = nButtons[i].value;isValid = true}
}
if (isForm.txtAuthorName.value === ""){alert('Please Enter The Authors Name')}
else if (isForm.txtPaperId.value == ""){alert('Please Enter The Paper ID')}
else if (isForm.txtTitle.value == ""){alert('Please Enter Paper Title')}
else if(isForm.txtTelNo.value ==""){alert('Please Enter Your Telephone No')}
else if(isForm.txtAddress.value ==""){alert('Please Enter Your Address')}
else if(isForm.txtPosition.value ==""){alert('You must choose your position ')}
else if (!isValid){alert('You must choose if you are a IEE Member ')}
else
{
alert("Author Name is: " + isForm.txtAuthorName.value + "." +"\n"+
"Paper ID is: " + isForm.txtPaperId.value + "." +"\n"+
"The Title Of The Paper is: " + isForm.txtTitle.value + "." +"\n"+
"The Telephone Number is: " + isForm.txtTelNo.value + "." +"\n"+
"Your Address is: " + isForm.txtAddress.value + "." +"\n"+
"Your Position is: " + isForm.txtPosition.value + "." +"\n"+
"Your Fax Number is: " + isForm.txtFax.value + "." +"\n"+
"Your Email address is: " + isForm.txtEmail.value + ".")
so is there no way that i can add to the code that i have already, or do i need to start again? The code that I already have displays the data exactlky as i need, it just needs to be placed in an array, purely to show that it can be done...
Many Thanks
Every input type text value is put into an array, just as you asked.
What is it that you don't understand, about this?:
var dataArray = new Array();
function validEntries(isForm){
n=0;
nElements = isForm.length;
for (i=0; i<nElements; i++)
{
if (isForm[i].type == 'text')
{
dataArray[n++] = isForm[i].value;
}
}
alert(dataArray);
isValid = false;
nButtons = document.getElementsByName('optS_Class');
for (i=0; i<nButtons.length; i++)
{
if (nButtons[i].checked == true){className = nButtons[i].value;isValid = true}
}
if (isForm.txtAuthorName.value === ""){alert('Please Enter The Authors Name')}
else if (isForm.txtPaperId.value == ""){alert('Please Enter The Paper ID')}
else if (isForm.txtTitle.value == ""){alert('Please Enter Paper Title')}
else if(isForm.txtTelNo.value ==""){alert('Please Enter Your Telephone No')}
else if(isForm.txtAddress.value ==""){alert('Please Enter Your Address')}
else if(isForm.txtPosition.value ==""){alert('You must choose your position ')}
else if (!isValid){alert('You must choose if you are a IEE Member ')}
else
{
alert("Author Name is: " + isForm.txtAuthorName.value + "." +"\n"+
"Paper ID is: " + isForm.txtPaperId.value + "." +"\n"+
"The Title Of The Paper is: " + isForm.txtTitle.value + "." +"\n"+
"The Telephone Number is: " + isForm.txtTelNo.value + "." +"\n"+
"Your Address is: " + isForm.txtAddress.value + "." +"\n"+
"Your Position is: " + isForm.txtPosition.value + "." +"\n"+
"Your Fax Number is: " + isForm.txtFax.value + "." +"\n"+
"Your Email address is: " + isForm.txtEmail.value + ".")
Bookmarks