Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form not working

    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:
    PHP Code:
    <?
    $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>

  • #2
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can anyone help me please?

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    give your function a name that isn't used by an element and it should work.
    Absolutely nothing to do with php though...

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    "<?=" is s shortcut for echoing things

  • #5
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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 Code:
    <?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>

  • #7
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok. Thank you all for your efforts and help ! I finally found it myself. This is the code i am using :
    PHP Code:
    <?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>

  • #9
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But still: thank you a lot!
    Last edited by arne2; 11-12-2006 at 04:02 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •