...

View Full Version : Validation of radio and text elements that returns a confirm



hugeusrealeus
08-19-2004, 09:09 AM
Hello all Sorry to post such a long but easy question. I am trying to have a
form filled with about 60 radio buttons and 1 text box validated to return a
error only if a button and the text field are filled in. I am not a programer
although I can use a little perl but I really am under alot of pressure to get
this done.
The code I am ussing already validates the form but only returns a ALERT if
there is no selection made. I NEED to return a CONFIRM to that clears the
text field if there is a radio button chosen. I am usiing a external js file cuase
the customer requests it, but any changes other wise are ok.
I have tried to modify this code to send a Confirm when both statements are
true but I can not find where it validates the text box, and every attempt at

changing the code has ended badly (No Confirm or alert, server error or nothing at all the worst in my opinion).

Any help would be greatly appreciated. There is some one standing over my shoulder
who looks like this :mad: , I am bigger than him but he signs the paychecks!!!! :eek:



<!--
var WC_ERRORS = '';
var wc_pageID = "jpissother";
function validate(form) {
var cardIssuer_Checked = false;
var Alert = '';

for (var i=0;i<form.issuer.length;i++)
{if(form.issuer[i].checked){cardIssuer_Checked=true;break;}}
if(!cardIssuer_Checked){Alert+="\n\n ERROR MSSG";WC_ERRORS+="No_Issuer_Checked;";}
if(!Alert){return true;}else{alert("ALERTMSSG"+Alert);return false;}}
//-->



Here is also a sample of the page I am working with.

<script src="/jpbile2004/js/other-issuers-validation-1.js" type="text/javascript"></script>


</head>

<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0"
rightmargin="0" marginheight="0" marginwidth="0"
text="#000000" link="#666633" vlink="#999999" alink="#999966">

<form action="/jp-mobile2004/selectOtherIssuer.do" method="post" >
<!--あ-->
<a name="a"></a>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#349999">
<tr>
<td>
<table border="0" width="100%" cellspacing="1" cellpadding="3" class="text">
<tr bgcolor="#B7EBEB">
<td width="100%" align="left" valign="top" colspan="2">あ</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="5%" align="left" valign="top">
<input type="radio" name="issuer" value="1_1¦">
</td>
<td width="95%" align="left" valign="top">

</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="14_1¦">
</td>
<td align="left" valign="top">

</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="1_2¦">
</td>
<td align="left" valign="top">

</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="1_3¦">
</td>
<td align="left" valign="top">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="4_2¦">
</td>
<td align="left" valign="top">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="4_13_1¦">
</td>
<td align="left" valign="top">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="13_3¦">
</td>
<td align="left" valign="top">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="13_1¦">
</td>
<td align="left" valign="top">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="13_2¦">
</td>
<td align="left" valign="top">
text1 </td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left" valign="top">
<input type="radio" name="issuer" value="15_1">
</td>
<td align="left" valign="top">
text2
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="100%" align="left" valign="top" colspan="2"><a href="#other"></a></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="100%" align="right" valign="top" colspan="2">
<input type="submit" name="action_entry_confirm" style="font-size:10pt;" value="text2" onclick="return validate(form)>
&nbsp;
<input type="reset" style="font-size:10pt;" value="text3">  
<a href="#top">▲Top</a>

</tr>
<!--Start textbox-->
<tr>
<td align="right">

<a name="other"></a>
<table border="0" width="100%" cellspacing="1"
cellpadding="5" bgcolor="#B7EBEB" class="copy">
<tr valign="top">
<td align="left">
text4a
</td>
</tr>
<tr valign="top">
<td bgcolor="#FFFFFF" align="center">
text5:<input type="TEXT" name="Issuer-text" value="" size="30"
maxlength="200"> <input type="submit"
name="action_entry_confirm" style="font-size:10pt;"
value="text6" onclick="return validate(form)>

123<input type="reset" style="font-size:10pt;" value="XX">
</td>
</tr>
</table>
</form>
</td>
</tr>
<!--End textbox-->

</table><!-- END OF MAIN CONTENT -->
<!--content end-->
</body>
</html>

I hope someone can please be of assitance I will
:thumbsup:

Thanks in Advance Erin

Kor
08-20-2004, 08:35 AM
Your code seems a little bit confusing for me. I don't see which is your final need... Can you explain what your form must do?

First, I see that you have two submit buttons for your form which is not a very bright ideea...

Second, the validate function must be handled by onsubmit event, placed in form tag, not by onclick event placed in button tag. The reason is simple: if fired by onclick, the validate function will submit the form anyway, nomatter the validadate conditions are fulfiled or not.

What kind of confirm you need? Confirm what?

hugeusrealeus
08-20-2004, 09:44 AM
KOR
Thanks for your reply... I understand this form seams shaky... our client (a very LARGE corporation) has passed this down from on high, I am not really a designer or a coder just some one who was told to make it happen. I would love to change form, I also personally would have used drop down boxes. I may be able to sneak in a extra tag and will change change the code to submit correctly after being checked but any change to the visual will cause serious problems.
Regardless...... I need the confirm to check for 2 true’s one in the radio fields and one in the text fields if both of those are true (filled in) then set off a confirm that says do you want to clear the text field. OK clears the text filed then submits and the form. Cancel returns the user to the page.
It sounds so simple to me but I have been killing myself to make it happen.


Now if you need your Linux server and your windows servers to jump off the rack, kiss and then dance around the room singing "Papa’s got a brand new bag!" all while streaming live video of the event to the world,,,,,,then I am your man. :thumbsup:
Thanks Again
E./

Kor
08-20-2004, 10:50 AM
Something like this?



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function validate(f){
if(f.elements['Issuer-text'].value.length<1){
alert('Please insert text in text field!');
f.elements['Issuer-text'].focus();
return false;
}
var q=0;
for (var i=0;i<f.elements.length;i++){
if(f.elements[i].type=='radio'){
if(f.elements[i].checked){
q++;
}
}
}
if(q==0){
alert('Please, check a radio button!');
return false;
}
var con = confirm('Do you want to submit?')
if(con){
f.elements['Issuer-text'].value='';
return true;
}
else if(!con){
return false;
}
}
</script>
</head>

<body>
<form onsubmit="return validate(this)">
<input name="issuer" type="radio" value="">
<br>
<input name="issuer" type="radio" value="">
<br>
<input name="issuer" type="radio" value="">
<br>
<input name="Issuer-text" type="text"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

hugeusrealeus
08-22-2004, 02:18 PM
KOR Thanks That is EXACTLY it .... much respect and thanks! If you ever need any streaming media help let me know!

Kor
08-23-2004, 08:27 AM
Glad to have helped you!



If you ever need any streaming media help let me know!


The only live streaming media I would like to acces is that of Manchester United Official Site (live soccer matches) :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum