Jump to content
php.lv forumi
  • 0

mainīt formas action atkarībā no padotā POST parametra


atikons

Question

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 atikons
Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

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

Link to comment
Share on other sites

  • 0

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>

Link to comment
Share on other sites

  • 0

+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;?>">

 

...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...