The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Form Problem, Trouble with Javascript and Method=Post
Hitokage
post May 29 2009, 07:56 AM
Post #1





Group: Members
Posts: 1
Joined: 29-May 09
Member No.: 8,739



I have a javascript below that forces someone filling out the form to fill out all of the blanks before submitting and won't let them submit until they have filled it all out. The problem is that the end of it is conflicting with the
QUOTE
method="post" action="http://fp1.formmail.com/cgi-bin/fm192"
part so that the form isn't submitting to our 3rd party site. Can anyone figure out how to fix this?

QUOTE
<script language="JavaScript">
<!--

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("Name", "EMail", "ZipCode", "Topic", "Provider", "Comment");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Name", "E-Mail", "Zip Code", "Topic", "Provider", "Comment/Question");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}

if (alertMsg.length == l_Msg){
alert("Thank you for contacting us here at myFOXnepa.com!")
return false;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>

<form name="formcheck" onsubmit="return formCheck(this);" method="post" action="http://fp1.formmail.com/cgi-bin/fm192">
<input type="hidden" name="recipient" value="1" />
<input type="hidden" name="_pid" value="55940" />
<input type="hidden" name="_fid" value="H7ZA3PWK" />
<input type="hidden" name="print_config" value="email" />
<input type="hidden" name="subject" value="myFOXnepa.com Contact Us" />
<table width="200" border="0">
<tr>
<td background="http://media.myfoxnepa.com/special/contactus/contactus_top.jpg" style="background-repeat:no-repeat; padding-left:15px"><span class='fontStyle1'>Contact Us</span> </td>
</tr>
<tr>
<td background="http://media.myfoxnepa.com/special/contactus/contactus_middle.jpg" style="background-repeat: repeat-y"><table width="658" border="0" cellpadding="8" cellspacing="0">
<tr>
<td width="124" align="right" nowrap><div align="center">Name:</div></td>
<td width="518"><input type="text" name="Name" size="50"></td>
</tr>
<tr>
<td align="right" nowrap><div align="center">E-Mail :</div></td>
<td><input name="EMail" type="text" id="EMail" size="50"></td>
</tr>
<tr>
<td align="right" nowrap><div align="center">Zip Code :</div></td>
<td><input name="ZipCode" type="text" id="ZipCode" size="5"></td>
</tr>
<tr>
<td align="right" valign="top" nowrap><div align="center">Topic:</div></td>
<td><label>
<select name="Topic" id="Topic">
<option value="Select" selected></option>
<option value="Sports">Sports</option>
<option value="Technical Issues">Technical Issues</option>
<option value="TV Programs">TV Programs</option>
<option value="Community Calendar">Community Calendar</option>
<option value="Website Issues/Questions">Website Issues/Questions</option>
</select>
</label></td>
</tr>
<tr>
<td align="right" valign="top" nowrap><div align="center">Provider:</div></td>
<td><label>
<select name="Provider" id="Provider">
<option value="Select" selected></option>
<option value="Adams">Adams</option>
<option value="Atlantic Broadband">Atlantic Broadband</option>
<option value="Bastress TV">Bastress TV</option>
<option value="Beaver Valley">Beaver Valley</option>
<option value="Blue Ridge">Blue Ridge</option>
<option value="Blue Mountain">Blue Mountain</option>
<option value="CATV">CATV</option>
<option value="Cebridge Connection">Cebridge Connection</option>
<option value="Cedar Run">Cedar Run</option>
<option value="Comcast">Comcast</option>
<option value="Community Cable">Community Cable</option>
<option value="D and E Communications">D and E Communications</option>
<option value="DirecTV">DirecTV</option>
<option value="Eagle Lake">Eagle Lake</option>
<option value="Eastville">Eastville</option>
<option value="Echo Star">Echo Star</option>
<option value="Hancock Video">Hancock Video</option>
<option value="Herr Cable">Herr Cable</option>
<option value="JC Cable">JC Cable</option>
<option value="Loganton TV">Loganton TV</option>
<option value="Metrocast">Metrocast</option>
<option value="Monument">Monument</option>
<option value="Nittany Media">Nittany Media</option>
<option value="North-Eastern PA Telephone Co.">North-Eastern PA Telephone Co.</option>
<option value="North Penn">North Penn</option>
<option value="Pikes Peak TV Association">Pikes Peak TV Association</option>
<option value="Retel">Retel</option>
<option value="Service Electric">Service Electric</option>
<option value="Shen Heights">Shen Heights</option>
<option value="Southside Service">Southside Service</option>
<option value="Time Warner">Time Warner</option>
<option value="Tylersville Community">Tylersville Community</option>
<option value="Wire Tele-View Corporation">Wire Tele-View Corporation</option>
</select>
</label></td>
</tr>
<tr>
<td align="right" nowrap><div align="center">Comment/Question :</div></td>
<td><textarea name="Comment" cols="60" rows="10" id="Comment"></textarea></td>
</tr>
<tr>
<td height="57" colspan="2" class="center"><div align="center">

<input type="submit" name="thebutton2" value="Submit Information" />
&nbsp;
<input type="reset" value="Cancel" name="button2" />
</span><br />
</p></td>
</tr>
</form>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post May 29 2009, 10:47 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



Try setting the onsubmit="return formCheck(this);" in the <input type="submit"...> instead of in the <form> tag.

HTH
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 29 2009, 02:48 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,661
Joined: 10-August 06
Member No.: 7



Don't understand all parts of the script, but shouldn't this

CODE
if (alertMsg.length == l_Msg){
alert("Thank you for contacting us here at myFOXnepa.com!")
return false;
}

contain a "return true" instead of "return false"?


QUOTE(Frederiek @ May 29 2009, 05:47 PM) *

Try setting the onsubmit="return formCheck(this);" in the <input type="submit"...> instead of in the <form> tag.

HTH

No the ONSUBMIT event only applies to the FORM element: http://www.w3.org/TR/html401/interact/scri...l#adef-onsubmit
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post May 30 2009, 02:23 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



Ok, I wasn't sure, but didn't bother to search. Thanks, Christian.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 26th April 2024 - 11:23 PM