Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Problem with RadioButtons and JavaScript


Message #1 by "alain2" <alain@g...> on Mon, 24 Sep 2001 15:24:38
I've found the solution, for all the people who have the same problem.
RadioButtons are managed in an Array, see example on 
http://tech.irt.org/articles/js027/index.htm

false: field_descr[i] = document.fdbk_form.elements['field_value'+i].value;
true: field_value[i] = document.fdbk_form.elements['field_value'+i]
[j].value; 
 
> Hi, i've wrote a javascript for forms. So there is the new_edit.jsp 
(like 
> html) and a Javascript-File on which it depends. Whitout the 
RadioButtons 
> the form does work, but if i want to include them like in the following 
> files I will recieve in netscape the error: 
> 
> JavaScript Error:
> http://abc.com/form.js,
> line 58:
> field_value[i] has no properties. 
> 
> In the Internet Explorer:
> Line: 57
> Error: ?length? is not an object
> 
> Can you help me? Thanks &  Excuse my real bad English.
> 
> Alain
> 
> new_edit.jsp:
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
> <meta NAME="content-language" content="en"/>
> <SCRIPT LANGUAGE="JavaScript" SRC="form.js"></SCRIPT>
> <NOSCRIPT><link REL="stylesheet" HREF="/css/font.css"></NOSCRIPT>
> </head>
> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" 
> bgcolor="#FFFFFF" link="#666666" VLINK="#666666" ALINK="#666666" 
> onLoad="MM_preloadImages('/images/logo_claim.gif')">
> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 VSPACE="0" HSPACE="0">
>   <TR> 
>     <TD ALIGN=LEFT VALIGN=BOTTOM  colspan="4"> <IMG 
> SRC='images/title_feedback_form.gif' WIDTH='800' HEIGHT='40'></TD>
>   </TR>
> </table>
> <table BORDER=0 CELLSPACING=0 CELLPADDING=0 VSPACE="0" HSPACE="0">
>   <tr> 
>     <td ><img src="images/uspacer.gif" width="182" height="5" 
> border="0"></td>
>     <td bgcolor="#6699FF" width="1"><img src="/images/uspacer.gif" 
> width="1" height="1"></td>
>     <td ><img src="images/uspacer.gif" width="10" height="5" 
> border="0"></td>
>     <td width="520"> 
>       <form method='get' name='fdbk_form'>
> 	<br>
>         <p>Surname: 
>           <input type='hidden' name='field_descr1' value='Surname:'>
>           <br>
>           <input type='text' name='field_value1' size='25' 
maxlength='25' >
>         </p>
>         <p>Name: 
>           <input type='hidden' name='field_descr2' value='Name:'>
>           <br>
>           <input type='text' name='field_value2' size='25' 
maxlength='25' >
>         </p>
>         <p>Rating: 
>           <input type='hidden' name='field_descr3' value='Rating:'>
>           <br>
>           <input type='radio' name='field_value3' value='excellent'>
>           excellent <br>
>           <input type='radio' name='field_value3' value='well'>
>           well <br>
>         </p>
>         <p>E-Mail: 
>           <input type='hidden' name='field_descr4' value='E-Mail:'>
>           <br>
>           <input type='text' name='field_value4' size='50' 
maxlength='70' >
>         </p>
>         <p>Feedback: 
>           <input type='hidden' name='field_descr5' value='Feedback:'>
>           <br>
>           <textarea name='field_value5' cols='55' rows='5'></textarea>
>         </p>
>         <p> <a href="javascript:submit_check()"><img 
> src='images/submit.gif' width='60' height='25' 
> border='0'></a>     
>           <a href="javascript:document.fdbk_form.reset()"><img 
> src="images/clear.gif" width="60" height="25" border="0"></a> 
>           <input type="hidden" name="cycle">
> 	  <input type="hidden" name="subject">
> 	  <input type="hidden" name="start">
>         </p>
>       </form>
>     </td>
>     <td bgcolor="#6699FF" width="1"><img src="/images/uspacer.gif" 
> width="1" height="1"></td>
>   </tr>
> </table>
> </body>
> </html>
> 
//------------------------------------------------------------------------
> 
> form.js:
> 
> <!--
> function submit_check() { 
> 
> 	var temp = null;
> 	var subject_temp = null;
> 	
> 	i = 1;
> 	while (document.fdbk_form.elements['field_descr'+i]){		
> 	// max. Anzahl Felder bestimmen
> 		i++;
> 	}
> 	cycle = i;
> 
> 	this.document.fdbk_form.cycle.value = cycle;
> 
> 	if (location.search.length > 0) {
> 		temp = unescape(location.search.substring(1));
> 		subject_temp = temp.substring(8);
> 	}
> 
> 	if (temp != null) {
> 		this.document.fdbk_form.subject.value = subject_temp;
> 		if (document.referrer != '') {
>     			this.document.fdbk_form.start.value = 
> document.referrer;
> 		}
> 	}
> 	
> 
> 	var version = parseFloat (navigator.appVersion);
> 	if (navigator.appName.indexOf('Microsoft') != -1) {
> 		if ( version >= 5.0 || navigator.appVersion.indexOf(5.0) !
> = -1) {
> 			other();
> 		}
> 		else {
> 			ie4();
> 		}
> 	}
> 	else {
> 		other(); 		// or ie4() for testing preiview 
> function	
> 	}
> }
> 
> function ie4() {
> 	var ok;
> 	var field_descr = new Array(i);
> 	var field_value = new Array(i);
> 
> 	var confirm_content = "";
> 	var new_line = "\n";
> 	var confirm_text = "Please confirm:";
> 	var dots = " ...";
> 		
> 	i = 1;								
> 	// i wieder auf 1 setzen
> 	for (i=1; i <= cycle; i++) { 
> 		if(document.fdbk_form.elements['field_descr'+i]){
> 			field_descr[i] = document.fdbk_form.elements
> ['field_descr'+i].value;
> 			field_value[i] = document.fdbk_form.elements
> ['field_value'+i].value;
> 			if(document.fdbk_form.elements['field_value'+i]){
> 				if (field_value[i].length > 55) {
> 					if (field_value[i].length > 500) {
> 						field_value[i] = 
> field_value[i].substring(0,500);
> 						field_value[i] = 
> new_line.concat(field_value[i],dots);
> 					}	
> 					else {
> 						field_value[i] = 
> new_line.concat(field_value[i]);
> 					}
> 				}
> 			}
> 			confirm_content = confirm_content.concat
> (field_descr[i], " ", field_value[i], new_line, new_line); 
> 		}
> 	}
> 	
> 	ok = confirm(confirm_text.concat(new_line, new_line, 
> confirm_content));
> 	if (ok == true) {
> 		this.document.fdbk_form.action = 
> "/applications/feedback/send.jsp";
> 		document.fdbk_form.submit();
> 	}
> }
> 
> function other() {
> 	this.document.fdbk_form.action = 
> "/applications/feedback/new_conf.jsp"
> 	document.fdbk_form.submit(); }
> //-->

  Return to Index