...

View Full Version : form not working



arne2
11-11-2006, 12:09 PM
Hi, i'm having a problem with the form code that i'm trying to script.
The 'max chars' isn't counting down when someone types in something. Can anyone help me with this?

Here is the code I currently have:

<?
$maxchar=1500;
?>

<script language="javascript">
<!--
function mailorderoffers(form)
{ with (form)
{ sisa.value = <?=$maxchar?>-content.value.length;
if (parseInt(sisa.value)<0) { sisa.value = '0'; }
content.value = content.value.substr(0,<?=$maxchar?>);
}
return;
}
//-->
</script>


<form name='mailorderoffers' action='mypage.php' method='POST'>
<font size='4'><b>Contact</b></font>
<br>
<table width='475' border='0' cellpadding='0' cellspacing='0'>
<tr><td width='50%' height='24'>Receiver:</td>
<td width='50%' height='24'><i>
<select name=senndmsgto>
<option name=1 value=1> Technical </option>
<option name=2 value=2> Sales </option>
<option name=3 value=3> General </option>
<option name=4 value=4> Services </option>
<option name=5 value=5> Wholesale </option>
</select>
</i></td></tr>
<tr><td width='50%' height='24'>Subject</td>
<td width='50%' height='24'><input type='text' name='sub'></td></tr>
<tr><td width='50%' height='24'>Name</td>
<td width='50%' height='24'><input type='text' name='name'></td></tr>
<tr><td width='50%' height='24'>Telephone</td>
<td width='50%' height='24'><input type='text' name='tel'></td></tr>
<tr><td width='50%' height='24'>Message</td>
<td><?echo"<textarea max='$maxchar' name='content' COLS='40' ROWS='6' onKeyup='mailorderoffers(document.mailorderoffers);' RAP></textarea>";?>
<br>Max <?=$maxchar?> chars.<br><?echo"Chars left : <input type=\"text\" size=4 name=sisa maxlength=4 value=\"$maxchar\">";?></td></tr>

<br>
<tr>
<td width='50%' height='24'></td>
<td width='50%' height='24'><input type='submit' value='Send'></td>
</tr></form>

arne2
11-11-2006, 05:32 PM
can anyone help me please?

GJay
11-11-2006, 05:55 PM
give your function a name that isn't used by an element and it should work.
Absolutely nothing to do with php though...

GJay
11-11-2006, 06:06 PM
"<?=" is s shortcut for echoing things

ess
11-11-2006, 06:31 PM
I am not too sure if this would help...but try and open your PHP tags like so <?php instead of using <?. Also, check that you are able to use the scriptlet <?= on your server. Often it is disabled by default.

cheers,
ess

mlseim
11-11-2006, 07:10 PM
Here's my solution. I had to change several things to make it work.

One problem though. With a textarea, you can't control the maximum
number of characters... so in my example, when you get to 1500, the
textarea is disabled. You'll have to figure out a different way to stop the
characters from being typed, as disabling turns off the whole deal.

I tried changing focus and some other things, but no luck.

But, this will get you started:



<?php
$maxchar=1500;
?>

<html>
<head>
<script type='text/javascript'>
function chars_left(){
//Current character count
var current = document.getElementById('content').value.length;
//How many left?
var chars_left = <?=$maxchar?> - current;
if (chars_left<0) { chars_left = '0'; document.getElementById('content').disabled = 'true'; }
document.getElementById('sisa').innerHTML = chars_left;
}
</script>
</head>
<body>

<form name='mailorderoffers' action='mypage.php' method='POST'>
<font size='4'><b>Contact</b></font>
<br>
<table width='475' border='0' cellpadding='0' cellspacing='0'>
<tr><td width='50%' height='24'>Receiver:</td>
<td width='50%' height='24'><i>
<select name=senndmsgto>
<option name=1 value=1> Technical </option>
<option name=2 value=2> Sales </option>
<option name=3 value=3> General </option>
<option name=4 value=4> Services </option>
<option name=5 value=5> Wholesale </option>
</select>
</i></td></tr>
<tr><td width='50%' height='24'>Subject</td>
<td width='50%' height='24'><input type='text' name='sub'></td></tr>
<tr><td width='50%' height='24'>Name</td>
<td width='50%' height='24'><input type='text' name='name'></td></tr>
<tr><td width='50%' height='24'>Telephone</td>
<td width='50%' height='24'><input type='text' name='tel'></td></tr>
<tr><td width='50%' height='24'>Message</td>
<td><textarea id='content' name='content' onkeyup='javascript:chars_left();' id='content' rows='6' cols='40' wrap></textarea><br />
<br>Max <?=$maxchar?> chars.<br>
Characters left: <span id='sisa' syle='font-weight:bold;'><?=$maxchar?></span>.
</td></tr>
<br>
<tr>
<td width='50%' height='24'></td>
<td width='50%' height='24'><input type='submit' value='Send'></td>
</tr></form>

</body>
</html>

arne2
11-12-2006, 04:34 PM
But i have another website and at that website i can just make the chars that are beyond the max char dissappear ! They jsut disappear right after typing because of the substring, can't that be done here too?

arne2
11-12-2006, 04:40 PM
Ok. Thank you all for your efforts and help ! I finally found it myself. This is the code i am using :

<?php
$maxchar=1500;
?>

<html>
<head>
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
</head>
<body>

<form name='mailorderoffers' action='contact.php' method='POST'>
<font size='4'><b>Contact</b></font>
<br>
<table width='475' border='0' cellpadding='0' cellspacing='0'>
<tr><td width='50%' height='24'>Receiver:</td>
<td width='50%' height='24'><i>
<select name=senndmsgto>
<option name=1 value=1> Technical </option>
<option name=2 value=2> Sales </option>
<option name=3 value=3> General </option>
<option name=4 value=4> Services </option>
<option name=5 value=5> Wholesale </option>
</select>
</i></td></tr>
<tr><td width='50%' height='24'>Subject</td>
<td width='50%' height='24'><input type='text' name='sub'></td></tr>
<tr><td width='50%' height='24'>Name</td>
<td width='50%' height='24'><input type='text' name='name'></td></tr>
<tr><td width='50%' height='24'>Telephone</td>
<td width='50%' height='24'><input type='text' name='tel'></td></tr>
<tr><td width='50%' height='24'>Message</td>
<td><textarea name="msg" onKeyDown="limitText(this.form.msg,this.form.countdown,<?=$maxchar?>);" onKeyUp="limitText(this.form.msg,this.form.countdown,<?=$maxchar?>);" rows='6' cols='40' wrap></textarea><br />
<br>Max <?=$maxchar?> chars.<br>
Characters left: <input readonly type="text" name="countdown" size="2" value="<?=$maxchar?>">
</td></tr>
<br>
<tr>
<td width='50%' height='24'></td>
<td width='50%' height='24'><input type='submit' value='Send'></td>
</tr></form>

</body>
</html>

arne2
11-12-2006, 04:58 PM
But still: thank you a lot!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum