Forum Moderators: open

Message Too Old, No Replies

Textarea Submit Problem (javascript + php)

<textarea> won't submit

         

jman123

6:49 am on Feb 21, 2007 (gmt 0)

10+ Year Member



I can't get the <textarea> to submit along with the rest of my form. Can anyone please help?

This isn't my code, and I'm not a php or javascript coder (I only know html ). I've manipulated the form enough to get the radio buttons to submit successfully, but the <textarea> won't go through.

Any help would be most appreceiated,

----------------------------------
Here is the <head> code:

--------------------------------------------
<?php
ob_start();
if(isset($_POST['flag'])){// if starts
ob_start();
?>
<title>Services</title><table width="600" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="10%" colspan="2" class="arial_11_grey_bold_ style17"><b>From: download.php</b></td>
</tr>
<tr>
<td width="10%" class="arial_11_grey_bold_ style17" colspan="2">Was the information in this section useful?</td>
</tr>
<? if(isset($_POST['flag'])){?>
<tr>
<td width="10%" class="arial_11_grey_bold_ style17"><b>Answer:</b></td>
<td class="arial_11_grey_bold_ style17"><?=$_POST['flag']?></td>
</tr><? }?>

</table>

<? $data = ob_get_contents();
ob_end_clean();
$to = "me@example.com";
$from = '';
$subject ="Feedback Form";
$message = $data;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "To: ".$to."\r\n";
@mail($to, $subject,$message, $headers);

}//end of the if(isset($_POST[flag])){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>Pricing Strategy - Download</TITLE>
<META NAME="description" CONTENT="some description">
<META NAME="keywords" CONTENT="some keywords">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="Images/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
function frmSubmit(){
obj = document.frmFeedBack;

if(document.getElementById('radfeedback1').checked == false && document.getElementById('radfeedback2').checked == false && document.getElementById('radfeedback3').checked == false){
alert("Give the feedback by checking the radiobutton");
return false;
}

var sel="";

if(document.getElementById('radfeedback1').checked == true){
sel = document.getElementById('radfeedback1').value;
}
if(document.getElementById('radfeedback2').checked == true){
sel = document.getElementById('radfeedback2').value;
}
if(document.getElementById('radfeedback3').checked == true){
sel = document.getElementById('radfeedback3').value;
}
if(document.getElementById('radfeedback4').value == ""){
sel = document.getElementById('radfeedback4').value;
}
obj.flag.value = sel;
obj.submit();
}
</script>

</head>
--------------------------------------------

.......and here is the form code:

--------------------------------------------
<tr>
<td style="border:#CCCCCC solid 1px"><form name="frmFeedBack" method="post" action="">
<input type="hidden" name="flag" value="" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5%" height="22" bgcolor="#ED850C">&nbsp;</td>
<td width="95%" align="left" bgcolor="#ED850C"><img src="Images/feedback_txt1.gif" width="67" height="13" /></td>
</tr>
<tr>
<td height="40">&nbsp;</td>
<td align="left" class="arial-11-blue_bold_ style2 style5">Was the information in this section useful?</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11%" align="left"><input type="radio" name="radfeedback" id="radfeedback1" value="Yes" /></td>
<td width="12%" align="left" class="arial-12-black style2 style5">Yes</td>
<td width="13%" align="right"><input type="radio" name="radfeedback" id="radfeedback2" value=" Somewhat" /></td>
<td width="31%" align="center" class="arial-12-black style2 style5"> Somewhat</td>
<td width="12%" align="left"><input type="radio" name="radfeedback" id="radfeedback3" value="No" /></td>
<td width="21%" align="left" class="arial-12-black style2 style5">No</td>
</tr>
<tr>
<td align="left" colspan="6" class="arial-12-black style2 style5" style="padding-top:10px; padding-left:5px">Comments:</td>
</tr>
<tr>
<td align="center" colspan="6"><textarea rows="2" cols="22" name="radfeedback" id="radfeedback4"></textarea></td>
</tr>
</table></td>
</tr>
<tr>
<td height="40">&nbsp;</td>
<!--a href="mailto:me@example.com?&body=I am having trouble finding information on "-->
<td align="left"><img src="Images/submit3.jpg" width="58" height="21" onClick="javascript:frmSubmit();" /></td>
</tr>
</table>
</form></td>
</tr>
--------------------------------------------

I desperately need help on this. I can't figure it out:(

Thanks a million!

[edited by: jatar_k at 3:18 pm (utc) on Feb. 21, 2007]
[edit reason] removed specifics [/edit]

scriptmasterdel

6:42 pm on Feb 21, 2007 (gmt 0)

10+ Year Member



Your problem is that the radio buttons have the same name as the textarea field so it is not being picked up, try renaming the textarea and then that should work fine.

Good luck.

Del

rocknbil

9:02 pm on Feb 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard jman123!

Might I add . . . what if Javascript is disabled?

<img src="Images/submit3.jpg" width="58" height="21" onClick="javascript:frmSubmit();" />

You get nothing. Also, onClick of an image will not work in all browsers. At the bare minimum, change the above line as follows:

<input type="image" src="Images/submit3.jpg" width="58" height="21" onClick="return frmSubmit();" />

Your Javascript should return false in any case. This will prevent the form from submitting if an error is found. So I would modify frmSubmit() as follows:


function frmSubmit(){
obj = document.frmFeedBack;
if(document.getElementById('radfeedback1').checked == false &&
document.getElementById('radfeedback2').checked == false &&
document.getElementById('radfeedback3').checked == false){
alert("Give the feedback by checking the radiobutton");
}
else { obj.submit(); }
return false;
}

. . . and note that obj.submit() is eliminated from below. This will skip the submit on alert as expected and submit only if it passes your test. As for the code that follows, those values should only change on the initial load anyway. return false will prevent the form from it's normal behavior, submission on click - but if Javascript is disabled, it will allow it to submit normally.

Lastly, you no longer require the language attribute here:

<script type="text/javascript" language="javascript">