atikons Posted October 21, 2009 Report Share Posted October 21, 2009 (edited) Kā panākt ar javascript, lai formai mainītos action URL atkarībā no padotā POST parametra, kas ir <input type=hidden name=test value=1 /> Vajag trīs iepriekš definētus URL, katru savam, piem: ja <input type=hidden name=test value=1 />, tad <FORM action = url_1 ja <input type=hidden name=test value=2 />, tad <FORM action = url_2 ja <input type=hidden name=test value=3 />, tad <FORM action = url_3 Ar Javascript pieredzes tik pat kā nav. Edited October 21, 2009 by atikons Quote Link to comment Share on other sites More sharing options...
0 indoom Posted October 21, 2009 Report Share Posted October 21, 2009 document.forms[0].action = 'url_' + document.forms[0].test.value; Quote Link to comment Share on other sites More sharing options...
0 atikons Posted October 21, 2009 Author Report Share Posted October 21, 2009 document.forms[0].action = 'url_' + document.forms[0].test.value; nedaudz neprecīzi saprati, domāju šādi: ja <input type=hidden name=test value=1 />, tad <FORM action = some_url.php ja <input type=hidden name=test value=2 />, tad <FORM action = other_url.php ja <input type=hidden name=test value=3 />, tad <FORM action = big_url.php Quote Link to comment Share on other sites More sharing options...
0 indoom Posted October 21, 2009 Report Share Posted October 21, 2009 kaut kur body beigās <script type="text/javascript"> document.forms[0].onsubmit = function(){ var val = this.test.value; switch(val) { case '1': this.action = 'some_url.php'; break; case '2': this.action = 'other_url.php'; break; case '3': this.action = 'big_url.php '; break; default: return false; } } </script> Quote Link to comment Share on other sites More sharing options...
0 mefisto Posted October 21, 2009 Report Share Posted October 21, 2009 Tā ir drausmīgi slikta ideja. Kāpēc tu vienkārši nevari apstrādāt POST datus servera pusē ? Quote Link to comment Share on other sites More sharing options...
0 briedis Posted October 21, 2009 Report Share Posted October 21, 2009 +1 par servera pusi! <?php $url = "nokluseetaaa_urla.php"; //ja tests nav ne 1 ne 2 ne 3 switch($test){ case 1 : $url = "first_url.php"; break; case 2 : $url = "otherurl.php"; break; case 3 : $url = "esmu_urla.php"; break; } ?> <form method="post" action="<?=$url;?>"> ... Quote Link to comment Share on other sites More sharing options...
0 mefisto Posted October 21, 2009 Report Share Posted October 21, 2009 Nē, tā gluži to es nebiju domājis. Quote Link to comment Share on other sites More sharing options...
0 briedis Posted October 21, 2009 Report Share Posted October 21, 2009 Nē, tā gluži to es nebiju domājis. Domā, sūtīt datus uz vienu skriptu, tad ar headeri pārsūtīt tālāk attiecībā no test lauka? :) Quote Link to comment Share on other sites More sharing options...
0 marcis Posted October 21, 2009 Report Share Posted October 21, 2009 Servera pusē pārbaudīt kura opcija ir izvēlēta un veikt attiecīgu darbību, tas arī viss. Quote Link to comment Share on other sites More sharing options...
0 briedis Posted October 21, 2009 Report Share Posted October 21, 2009 Servera pusē pārbaudīt kura opcija ir izvēlēta un veikt attiecīgu darbību, tas arī viss. Nu bet nevar zināt, kas viņam tur tajos urļos apakšā slēpjas. Moš milzu koda blāķi, kurus tomēr labāk nodalīt :)) Quote Link to comment Share on other sites More sharing options...
0 codez Posted October 21, 2009 Report Share Posted October 21, 2009 Moš viņam urļi uz dažādiem domeiniem. Quote Link to comment Share on other sites More sharing options...
0 marcis Posted October 21, 2009 Report Share Posted October 21, 2009 Koda blāķi var izsaukt arī pēc kaut kādas darbības, ja vispār dažādi domēni, tad jau gan cita tēma. Pirms sākt domāt risinājumus kaut kādai problēmai, tomēr jāizvērtē vai tu pats sev neradi šīs problēmas. Quote Link to comment Share on other sites More sharing options...
Question
atikons
Kā panākt ar javascript, lai formai mainītos action URL atkarībā no padotā POST parametra, kas ir <input type=hidden name=test value=1 />
Vajag trīs iepriekš definētus URL, katru savam, piem:
ja <input type=hidden name=test value=1 />, tad <FORM action = url_1
ja <input type=hidden name=test value=2 />, tad <FORM action = url_2
ja <input type=hidden name=test value=3 />, tad <FORM action = url_3
Ar Javascript pieredzes tik pat kā nav.
Edited by atikonsLink to comment
Share on other sites
11 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.