[Javascript] Multiple If Statements Not Working in Netscape

Tom Churm thomas.churm at pixelpark.com
Tue May 1 10:31:32 CDT 2001


Send To: javascript at egroups.com
hi,

i've been playing around trying to make a meta-search form by copying 
search-forms from various search engines.  the form worked great, but then 
i added checkboxes.  if a checkbox is checked, then the words entered into 
the search-form should be automatically searched by all of the 
search-engines checked.  the code below works in MSIE but not in 
Netscape--in netscape it only searches in the last search engine checked, 
and i think it's due to the syntax of my JavaScript--i have a whole lot of 
If statements here and NS doesn't process them correctly--it's like it 
reads them as "if else" statements instead of as a bunch of separate If 
statements.

i know that i could write my If statements like:
if ((document.sameValue.goo.checked == 
true)&&(document.sameValue.lyc.checked == true)){
         document.forms[1].submit();
         document.forms[2].submit();
         }

but i would have to write long, complicated if statements for all 
permutations:  1 searchbox checked, 2 searchboxes checked,  2 other 
searchboxes checked, etc...

there's gotta be an easier way, i just don't have a clue what it is.

any hints would be great!

thanks,

tom

 >>>>>>>CODE FOLLOWS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<html>
<head>
         <title></title>
         <script language="JavaScript">
<!--
/*This function called when user clicks on Submit link*/
function sendAll() {

/*Define defaultValue*/
var defaultValue = document.sameValue.allInputs.value;

/*Give all forms same defaultValue*/
document.forms[1].q.value = defaultValue;
document.forms[2].query.value = defaultValue;
document.forms[3].p.value = defaultValue;
document.forms[4].q.value = defaultValue;
document.forms[5].elements[1].value = defaultValue;

/*Send off all forms if the right checkbox is checked*/
if (document.sameValue.goo.checked == true){
         document.forms[1].submit();
         }
if (document.sameValue.lyc.checked == true){
         document.forms[2].submit();
         }
if (document.sameValue.yah.checked == true){
         document.forms[3].submit();
         }
if (document.sameValue.fir.checked == true){
         document.forms[4].submit();
         }
if (document.sameValue.con.checked == true){
         document.forms[5].submit();
         }

}
//-->
</script>
</head>

<body text="#000000" bgcolor="#dfdfdf" topmargin="0" leftmargin="0" 
rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0">

<h2>MetaSearch Test</h2><br>

<form name="sameValue" id="sameValue" onSubmit="sendAll()">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
     <td>google.de</td>
     <td><input type="checkbox" name="goo" value="" checked></td>
</tr>
<tr>
     <td>lycos.de</td>
     <td><input type="checkbox" name="lyc" value="" checked></td>
</tr>
<tr>
     <td>yahoo.de</td>
     <td><input type="checkbox" name="yah" value="" checked></td>
</tr>
<tr>
     <td>fireball.de</td>
     <td><input type="checkbox" name="fir" value="" checked></td>
</tr>
<tr>
     <td>conrad.com</td>
     <td><input type="checkbox" name="con" value="" checked></td>
</tr>
</table>

<input type="text" name="allInputs" size=25 maxlength=50>
<br>
<a href="javascript:sendAll()">Submit</a>
</form>



<!--  Google-->
<form action=http://www.google.de/search method=get name=f target="_blank">
<input type=hidden value="" name=q size=50 maxlength=256><br><input name=hl 
type=hidden value=de>
<input type=hidden name=meta value="lr=lang_de">
</form>

<!--  Lycos-->
<FORM ACTION="http://www.lycos.de/cgi-bin/pursuit" METHOD="GET" 
NAME="mainform" target="_blank">
<input type="hidden" name="matchmode" value="and">
<input type="hidden" name="mtemp" value="main">
<input type="hidden" name="etemp" value="error">
<INPUT TYPE="hidden" NAME="query" SIZE="30">
<INPUT TYPE="hidden" NAME="cat" VALUE="de_spkr" CHECKED>
</form>

<!--  Yahoo-->
<form action="http://de.search.yahoo.com/search/de" target="_blank">
<input type=hidden name=p size=30>
</form>

<!-- Fireball -->
<form method="GET" action="http://suche.fireball.de/fcgi/query.fcg" 
target="_blank">
<input type="hidden" name="action" value="query"><input type="hidden" 
name="pg" value="express">
<input type="hidden" name="q" size="25">
<input type="hidden" name="what" value="german_web">
</form>

<!--  conrad.com-->
<form action="http://www.conrad.de/cgi-bin/conshop/index.cgi" method="get" 
target="_blank"><input type="hidden" name="PP_EV[SEARCHINIT]" value="1">
<input type="hidden" name="PP_PAR[SEARCHTEXT]" size=15 maxlength=50>
</form>

</body>
</html>





More information about the Javascript mailing list