rares_dumitrescu
asked on
javascript
<script language="javascript" type="text/javascript">
function chk_form() {
document.forms['comment']. nick.disab led = false;
alert(document.forms['comm ent'].show _list.chec ked);
if (document.forms['comment'] .show_list .checked) {
if ((document.forms['comment' ].prieten. value == "") && (!document.forms['comment' ].to_all.c hecked)) { alert('Nu ai selectat nici un destinatar.'); return false }
else {
if (document.forms['comment'] .subiect.v alue == "") { 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.ch ecked) { 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.valu e == "") { alert('Nu ai selectat nici un destinatar.'); return false }
else {
if (document.forms['comment'] .subiect.v alue == "") { 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.disab led = true;
document.forms['comment']. showlist.d isabled = true;
var htmllist = "<select name=\"prieten\" class=\"imput\" id=\"judet\"><option value=\"\" selected>Alege Prieten</option><option value=\"\">--------------- -----</opt ion></sele ct> <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('t o_form').i nnerHTML=h tmllist } else { document.getElementById('t o_form').i nnerHTML=h tmlnick };"> <label for="show_list">Arata lista prieteni</label>
</td>
</tr>
</tr>
<tr>
<td class="text-search"><b>Sub iect:</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_smile y(':D')">< img alt=":D" src="../imagini/smiley/1.g if" border=0></a> <a href="javascript:add_smile y(':)')">< img alt=":)" src="../imagini/smiley/2.g if" border=0></a> <a href="javascript:add_smile y(':(')">< img alt=":(" src="../imagini/smiley/3.g if" border=0></a> <a href="javascript:add_smile y(':o')">< img alt=":o" src="../imagini/smiley/4.g if" border=0></a> <a href="javascript:add_smile y(':shock: ')"><img alt=":shock:" src="../imagini/smiley/5.g if" border=0></a>
<a href="javascript:add_smile y(':?')">< img alt=":?" src="../imagini/smiley/6.g if" border=0></a> <a href="javascript:add_smile y('8)')">< img alt="8)" src="../imagini/smiley/7.g if" border=0></a> <a href="javascript:add_smile y(':lol:') "><img alt=":lol:" src="../imagini/smiley/8.g if" border=0></a> <a href="javascript:add_smile y(':x')">< img alt=":x" src="../imagini/smiley/9.g if" border=0></a> <a href="javascript:add_smile y(':P')">< img alt=":P" src="../imagini/smiley/10. gif" border=0></a><br>
<a href="javascript:add_smile y(':oops:' )"><img alt=":oops:" src="../imagini/smiley/11. gif" border=0></a> <a href="javascript:add_smile y(':cry:') "><img alt=":cry:" src="../imagini/smiley/12. gif" border=0></a> <a href="javascript:add_smile y(':twiste d:')"><img alt=":twisted:" src="../imagini/smiley/13. gif" border=0></a> <a href="javascript:add_smile y(':roll:' )"><img alt=":roll:" src="../imagini/smiley/14. gif" border=0></a> <a href="javascript:add_smile y(':wink:' )"><img alt=":wink:" src="../imagini/smiley/15. gif" border=0></a>
<a href="javascript:add_smile y(':!:')"> <img alt=":!:" src="../imagini/smiley/16. gif" border=0></a> <a href="javascript:add_smile y(':?:')"> <img alt=":?:" src="../imagini/smiley/17. gif" border=0></a> <a href="javascript:add_smile y(':arrow: ')"><img alt=":arrow:" src="../imagini/smiley/18. gif" border=0></a> <a href="javascript:add_smile y(':|')">< img alt=":|" src="../imagini/smiley/19. gif" border=0></a> <a href="javascript:add_smile y(':mrgree n:')"><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 ?
function chk_form() {
document.forms['comment'].
alert(document.forms['comm
if (document.forms['comment']
if ((document.forms['comment'
else {
if (document.forms['comment']
if (document.forms['comment']
if (document.forms['comment']
return true;
};
} else {
if (document.forms['comment']
else {
if (document.forms['comment']
if (document.forms['comment']
return true;
};
};
};
function disable_field(user) {
document.forms['comment'].
document.forms['comment'].
document.forms['comment'].
var htmllist = "<select name=\"prieten\" class=\"imput\" id=\"judet\"><option value=\"\" selected>Alege Prieten</option><option value=\"\">---------------
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
<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('t
</td>
</tr>
</tr>
<tr>
<td class="text-search"><b>Sub
<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 class="text-search" valign="top">
<textarea name="com" cols="34" rows="6" class="imput"></textarea><
<div align="left">
<a href="javascript:add_smile
<a href="javascript:add_smile
<a href="javascript:add_smile
<a href="javascript:add_smile
</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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
they are visible and working, just the validation doesn't work
but they are diplayed properly