Solved

javascript

Posted on 2006-06-16
3
362 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
ID: 16921342
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
ID: 16921599
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
ID: 16921761
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

685 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