NBS Posted September 5, 2008 Report Share Posted September 5, 2008 Sveiki, izpalīdziet, lūdzu. Ja neatzīmē nevienu radio pogu tad izmet alert(). Neizdodas :( JS: function check(form){ var form = document.getElementByName('form'); var inphone = document.getElementByID('inphone'); var outphone = document.getElementByID('outphone'); if (inphone.checked = false || outphone.checked = false) { alert('Ievadiet zvana veidu!'); result = false; } return true; } Forma: <form name="form" action="#" method="POST" onSubmit="return check(this);"> Radio buttons: <td><b>Zvans veikts:</b> ienākošais<input type="radio" id="inphone" name="phone" value="inphone" /> izejošais<input type="radio" id="outphone" name="phone" value="outphone" /> </td> Link to comment Share on other sites More sharing options...
Grey_Wolf Posted September 5, 2008 Report Share Posted September 5, 2008 salidzinasanas kljuda !!! [ = ] pieskjirsanas operators [ == ] salidzinasanas .. -- inphone.checked = false --> pieskjir vertibu false inphone.checked == false --> parbaudi vertibu (vai nav vienada ar false ) Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 salidzinasanas kljuda !!![ = ] pieskjirsanas operators [ == ] salidzinasanas .. -- inphone.checked = false --> pieskjir vertibu false inphone.checked == false --> parbaudi vertibu (vai nav vienada ar false ) Pārmainiju, bet diemžēl nepalīdzēja :( Link to comment Share on other sites More sharing options...
codez Posted September 5, 2008 Report Share Posted September 5, 2008 vajag nevis OR, bet AND -> && Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 vajag nevis OR, bet AND -> && Man tieši vajag tā, ka viena no radio pogām obligāti ir atzīmēta, neviss abas un ka neviena. Link to comment Share on other sites More sharing options...
Aleksejs Posted September 5, 2008 Report Share Posted September 5, 2008 (edited) Tāpēc, ka alerts jāparāda, kad gan viens, gan otrs ir false. Nevis, kad kaut viens no viņiem ir false. Nu, ja Tev vajag variantu, kad tieši viena no viņām ir, tad jāizmanto XOR: (poga1.checked ^ poga2.checked) == true Edited September 5, 2008 by Aleksejs Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 Tāpēc, ka alerts jāparāda, kad gan viens, gan otrs ir false. Nevis, kad kaut viens no viņiem ir false.Nu, ja Tev vajag variantu, kad tieši viena no viņām ir, tad jāizmanto XOR: (poga1.checked ^ poga2.checked) == true Izmainiju uz šo: if ((inphone.checked ^ outphone.checked) == true) { Meiģināju arī: if (inphone.checked ^ outphone.checked) == true { Nepalīdz :( Besī, ka errorus nemet, kad nepareizi izpildās JS :( Link to comment Share on other sites More sharing options...
codez Posted September 5, 2008 Report Share Posted September 5, 2008 (edited) tad inphone.checked != outphone.checked EDIT: tphu, kļudu jāizmet tad, ja inphone.checked == outphone.checked Edited September 5, 2008 by codez Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 tadinphone.checked != outphone.checked EDIT: tphu, kļudu jāizmet tad, ja inphone.checked == outphone.checked Jau paspēju abus notestēt, neizprotu, kas par sviestu :( Man varbūt kaut kur trūkst, ka šīm radio pogām vajag uzstādīt ar JS, ka tie ir checked vai arī pietiek ar to, ka lietotājs to tikai atzīmē un pie submit JS pārbauda. Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 (edited) Ievēroju baigo bonusu: Alert neizmetās... function check(form) { var form = document.getElementByName('form'); var inphone = document.getElementByID('inphone'); var outphone = document.getElementByID('outphone'); alert(inphone); if (inphone.checked == outphone.checked) { alert('Ievadiet zvana veidu!'); result = false; } return true; } html kods: <td> <b>Zvans veikts:</b> ienākošais<input type="radio" id="inphone" name="phone" value="inphone" /> izejošais<input type="radio" id="outphone" name="phone" value="outphone" /> </td> Edited September 5, 2008 by NBS Link to comment Share on other sites More sharing options...
indoom Posted September 5, 2008 Report Share Posted September 5, 2008 varbūt iekšā tā if pārbaudes derētu ielikt arī return false;, lai forma neizpildās, kad ir tas alerts. Bez tam radio pogām ar vienādu name, nemaz nevar atzīmēt abus. Tā kā mierīgi varēji izmanto jau to, ko sākumā codez teica function check(form){ if (!form.phone[0].checked && !form.phone[1].checked) { alert('Ievadiet zvana veidu!'); return false; } return true; } Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 Es esmu galīgs idiots, jo man neizdodas :( function check(form) { var form = document.getElementByName('form'); var inphone = document.getElementByID('inphone'); var outphone = document.getElementByID('outphone'); if (!form.inphone.checked && !form.outphone.checked) { alert('Ievadiet zvana veidu!'); return false; } return true; } Link to comment Share on other sites More sharing options...
tomaac Posted September 5, 2008 Report Share Posted September 5, 2008 (edited) function check(a) { //var form = document.getElementByName('forma'); var inphone = document.getElementById('inphone'); var outphone = document.getElementById('outphone'); // alert(inphone); if (inphone.checked == outphone.checked) { alert('Ievadiet zvana veidu!'); return false; } return true; } </SCRIPT> <form name="forma" action="#" method="POST" onSubmit="return check(this);"> <td><b>Zvans veikts:</b> ienākošais<input type="radio" id="inphone" name="phone" value="inphone" /> izejošais<input type="radio" id="outphone" name="phone" value="outphone" /> <INPUT TYPE=SUBMIT VALUE="Submit"> </td> </FORM> Vai šādi neder? Edited September 5, 2008 by tomaac Link to comment Share on other sites More sharing options...
Paulinjsh Posted September 5, 2008 Report Share Posted September 5, 2008 kāpēc tad tu pirms inphone ifā liec form, tak tur pietiek vienkārši ar inphone. Link to comment Share on other sites More sharing options...
NBS Posted September 5, 2008 Author Report Share Posted September 5, 2008 (edited) Paldies, tomaac, beidzot iebraucu, kur kļūda man. Liels paldies, visiem! Es vienkārši esmu ar abām kreisajām... Edited September 5, 2008 by NBS Link to comment Share on other sites More sharing options...
Recommended Posts