Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

javascript

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


function chk_form() {
document.forms['comment'].nick.disabled = false;
    alert(document.forms['comment'].show_list.checked);
if (document.forms['comment'].show_list.checked) {

   if ((document.forms['comment'].prieten.value == "") && (!document.forms['comment'].to_all.checked)) { alert('Nu ai selectat nici un destinatar.'); return false }
   else {
    if (document.forms['comment'].subiect.value == "") { ret = confirm('Esti sigur(a) ca vrei sa trimiti mesajul fara subiect?'); if(!ret) { return false; }; };
    if (document.forms['comment'].com.value == "") { ret = confirm('Esti sigur(a) ca vrei sa trimiti mesajul fara continut?'); if(!ret) { return false; }; };
    if (document.forms['comment'].to_all.checked) { ret = confirm('Esti sigur(a) ca vrei sa trimiti mesajul la toti prietenii?'); if(!ret) { return false; }; };
    return true;
   };
 } else {
   if (document.forms['comment'].nick.value == "") { alert('Nu ai selectat nici un destinatar.'); return false }
   else {
    if (document.forms['comment'].subiect.value == "") { ret = confirm('Esti sigur(a) ca vrei sa trimiti mesajul fara subiect?'); if(!ret) { return false; }; };
    if (document.forms['comment'].com.value == "") { ret = confirm('Esti sigur(a) ca vrei sa trimiti mesajul fara continut?'); if(!ret) { return false; }; };
    return true;
  };

 };

};

function disable_field(user) {
document.forms['comment'].nick.value = user;
document.forms['comment'].nick.disabled = true;

document.forms['comment'].showlist.disabled = true;

var htmllist = "<select name=\"prieten\" class=\"imput\" id=\"judet\"><option value=\"\" selected>Alege Prieten</option><option value=\"\">--------------------</option></select> <input type=\"checkbox\" name=\"to_all\" value=\"to_all\" class=\"imput\"> <label for=\"to_all\">Trimite la toti</label>"
var htmlnick = "<input type=\"text\" name=\"nick\" maxlength=\"20\" size=\"35\" class=\"imput\">"

};



</script>


and the html code:

<form name="comment" method="post" action="sendm.php" onSubmit="if(chk_form()==0) { return false } else { return true }">
<imput type="hidden" name="selected" id="selected" value="0">
  <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td width="25%" class="text-search" valign="top" rowspan="2"> <b>Catre:</b></td>
      <td width="75%" class="text-search" valign="top">
       <div id="to_form">
        <input type="text" name="nick" maxlength="20" size="35" class="imput">
       </div>
      </td>
    </tr>
    <tr>
       <td class="text-search">
        <input type="checkbox" name="showlist" value="show" class="imput" id="show_list" onclick="if (this.checked) { document.getElementById('to_form').innerHTML=htmllist } else { document.getElementById('to_form').innerHTML=htmlnick };"> <label for="show_list">Arata lista prieteni</label>
       </td>
     </tr>
    </tr>
    <tr>
      <td class="text-search"><b>Subiect:</b></td>
      <td class="text-search">
        <input type="text" name="subiect" maxlength="35" size="35" class="imput">
      </td>
    </tr>
    <tr>
      <td class="text-search" valign="top"><b>Mesaj:</b></td>
      <td class="text-search" valign="top">
        <textarea name="com" cols="34" rows="6" class="imput"></textarea><br>
        <div align="left">

         <a href="javascript:add_smiley(':D')"><img alt=":D" src="../imagini/smiley/1.gif" border=0></a> <a href="javascript:add_smiley(':)')"><img alt=":)" src="../imagini/smiley/2.gif" border=0></a> <a href="javascript:add_smiley(':(')"><img alt=":(" src="../imagini/smiley/3.gif" border=0></a> <a href="javascript:add_smiley(':o')"><img alt=":o" src="../imagini/smiley/4.gif" border=0></a> <a href="javascript:add_smiley(':shock:')"><img alt=":shock:" src="../imagini/smiley/5.gif" border=0></a>
         <a href="javascript:add_smiley(':?')"><img alt=":?" src="../imagini/smiley/6.gif" border=0></a> <a href="javascript:add_smiley('8)')"><img alt="8)" src="../imagini/smiley/7.gif" border=0></a> <a href="javascript:add_smiley(':lol:')"><img alt=":lol:" src="../imagini/smiley/8.gif" border=0></a> <a href="javascript:add_smiley(':x')"><img alt=":x" src="../imagini/smiley/9.gif" border=0></a> <a href="javascript:add_smiley(':P')"><img alt=":P" src="../imagini/smiley/10.gif" border=0></a><br>
         <a href="javascript:add_smiley(':oops:')"><img alt=":oops:" src="../imagini/smiley/11.gif" border=0></a> <a href="javascript:add_smiley(':cry:')"><img alt=":cry:" src="../imagini/smiley/12.gif" border=0></a> <a href="javascript:add_smiley(':twisted:')"><img alt=":twisted:" src="../imagini/smiley/13.gif" border=0></a> <a href="javascript:add_smiley(':roll:')"><img alt=":roll:" src="../imagini/smiley/14.gif" border=0></a> <a href="javascript:add_smiley(':wink:')"><img alt=":wink:" src="../imagini/smiley/15.gif" border=0></a>
         <a href="javascript:add_smiley(':!:')"><img alt=":!:" src="../imagini/smiley/16.gif" border=0></a> <a href="javascript:add_smiley(':?:')"><img alt=":?:" src="../imagini/smiley/17.gif" border=0></a> <a href="javascript:add_smiley(':arrow:')"><img alt=":arrow:" src="../imagini/smiley/18.gif" border=0></a> <a href="javascript:add_smiley(':|')"><img alt=":|" src="../imagini/smiley/19.gif" border=0></a> <a href="javascript:add_smiley(':mrgreen:')"><img alt=":mrgreen:" src="../imagini/smiley/20.gif" border=0></a>

        </div>
      </td>
    </tr>
    <tr>

      <td class="text-search" colspan="2">
        <div align="center"><input type="submit" name="submit" value="Trimite" class="button"></div>
      </td>
    </tr>
  </table>
</form>


if showlist is not checked a textfield appears ( htmlnick ) and when you click submit if that field is empty an alert error apperas.
When you check showlist a select field appears and a checkbox to_all ( htmllist ) the chk_form function shold check when submit is click if someone is selected from that list or the to_all is checkd.

This doesn't work. Any ideea why ?
0
rares_dumitrescu
Asked:
rares_dumitrescu
  • 2
1 Solution
 
bpmurrayCommented:
Move the definitions of htmlnick and htmllist to somewhere they can be "seen" by the JavaScript. In other words, move them from the disable_field function to just under the <script> tag:

<script language="javascript" type="text/javascript">
var htmllist = "<select name=\"prieten\" class=\"imput\" id=\"judet\"><option value=\"\" selected>Alege Prieten</option><option value=\"\">--------------------</option></select> <input type=\"checkbox\" name=\"to_all\" value=\"to_all\" class=\"imput\"> <label for=\"to_all\">Trimite la toti</label>"
var htmlnick = "<input type=\"text\" name=\"nick\" maxlength=\"20\" size=\"35\" class=\"imput\">"

etc...

Note that they are NOT inside a function.
0
 
rares_dumitrescuAuthor Commented:
they are somwhere else .. I've copyed them there when I posted here.
they are visible and working, just the validation doesn't work
but they are diplayed properly
0
 
bpmurrayCommented:
Ahh - can you post what's not working please: it's difficult to determine the problem if you only provide some of the information, and that's rejigged so that it has other bugs.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now