Forum Moderators: open

Message Too Old, No Replies

Should be simple form validation, but I'm new.. ;)

form validation question regarding textarea and radio buttons.

         

skizm

12:22 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Alrighty, I wouldnt normally ask for such blatent advice, but I'm losing my patience. I do stuff mainly in asp.net etc. but have this immediate need for clientside form validation. Here's my problem;

30+ form fields, some textareas, some checkboxes, some radiobuttons...

I need to check atleast the textareas and radio buttons to make sure they have been answered, if false than invoke alertbox and abort post. I had been trying this with no luck. please help! heh.

<script language="Javascript">
<!--
function checkData()
{
var correct = true;
var isChecked = false;

''''This for radio buttons''''

var radios = document.getElementsByTagName("three");
for (var i=0;i<radios.length;i++) {
if (radios[i].checked) isChecked = true; correct = false;
alert("Please answer number 3");
}

var radios = document.getElementsByTagName("five");
for (var i=0;i<radios.length;i++) {
if (radios[i].checked) isChecked = true; correct = false;
alert("Please answer number 5");
}

'''''This for textareas''''

if (document.LSL.one.value == ""){correct = false; alert("Please Enter Your Name"); form.one.focus();}

if (document.LSL.two.value == ""){correct = false; alert("Please Enter Your Age"); form.two.focus();}

if (correct){alert("Thank you "+document.LSL.one.value+"! Your results are pending review, expect notification of results as soon as possible...")}
return correct
}
//-->
</script>

----eof----

Now then, it seems to catch the text box's fine, but it still goes ahead an posts the data instead of aborting the script. Here's an example of how I have the form side stuff.

<form onSubmit="return checkData()" name="LSL" action="cgi-bin/custom-data.asp" method="post">

1. What is your first name?<br />
<input type="text" name="one"><br /><br />

2. What is your age and ethnicity? (This is so the software knows which sample population to compare you to. You wouldn't want to be compared to 50 y/o Whites if you're 20 y/o and Hispanic).<br />
<input type="text" name="two" size="2">&nbsp;Enter age here<br />
<input type="text" name="twoa" size="12">&nbsp;Enter ethnicity here<br/><br/>

I've really hit a wall here and am getting very frustrated. I would more than gladly send anyone whom helps this poort guy out a cold six pack on me! heh, thank you for taking the time...

ChadSEO

2:29 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



skizm,

I've seen a problem like this when I had an error in my JavaScript. One thing you could do is change the submit button to just a button (type="button") and add an onclick event to trigger the getData() function. Something like this:

<input type="button" value="Test" onclick="checkData();">

This will run the function without taking you to another page, so you will be able to check for any javascript errors that crop up.

Chad

skizm

12:07 am on Aug 24, 2005 (gmt 0)

10+ Year Member



Unfortunately I still cant get it to hold to the var correct = true and it posts data to the cgi script without breaking the process and restarting validation from the beginning.

Who can I ups a six pack to help my poor *** *** out with this?

[edited by: eelixduppy at 9:46 pm (utc) on Feb. 18, 2009]