Solved

javascript

Posted on 2006-06-16
3
358 Views
Last Modified: 2013-12-16
<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
Comment
Question by:rares_dumitrescu
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
bpmurray earned 500 total points
Comment Utility
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
 

Author Comment

by:rares_dumitrescu
Comment Utility
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
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now