0

I want to get the value depending on the check box checked. In Form action method" such that <Form action = importP2.php or importP3.php on click "SUBMIT" button.

HTML

<input type="checkbox" name="param[]" value="SH" id="SH" onclick="selectionListener();" />
<label for="SH">Synoptic Hour</label>
<br />
<input type="checkbox" name="param[]" value="DS" id="DS" onclick="selectionListener();" />
<label for="DS">Days Summery</label>

form action = " " method="post" onsubmit = ". SelectionMade ." enctype="multipart/form-data"

Script

function selectionListener() {

  checkedStr = '';

 if (document.getElementById('SH').checked) 
{          checkedStr = "importP2.php";       }


  if (document.getElementById('DS').checked)
 {         checkedStr = "importP3.php";      }
    
    document.getElementById('SelectionMade').value = checkedStr;

}
sumanta
  • 1
  • 2
  • under the SelectionMade variable – sumanta Aug 24 '20 at 05:32
  • So, what is stopping you from setting the action variable of the form then? It's unclear what you tried or what went wrong – ADyson Aug 24 '20 at 06:06
  • P.s. if you find yourself with 2 separate PHP scripts which accept the same input data, then you should consider whether they really ought to be just one script which uses an extra option field (in this case SH or PH options) to change (part of) the behaviour of the script. I can't see your current scripts but I'd guess there's probably quite a lot of repetition of code in both of them, and it can probably be made more efficient. – ADyson Aug 24 '20 at 06:08
  • Thanks ADyson for your Reply I can do this by two separate php page but as a part of my project it is difficult a little bit if there is no solution then I have to adopt your opinion. I have a php page with two option on basis of option and after upload a csv file the concerned php page will open but I can't able to set requires php script in the Form Action method so help me to short out the problem. Sorry for not proper way of posting. – sumanta Aug 24 '20 at 12:45
  • https://stackoverflow.com/a/61373182/5947043 shows you how to change a form's action. And 100 other similar answers online will also show you, if you do a basic search. You are certainly not the first person to have that requirement. Like I said, what have you researched? What have you tried? We don't know what "can't able to" means - does it mean you wrote some code which didn't work? or does it mean you didn't even start looking for a solution yet? On this site we prefer it if people make some effort to solve their own problem before asking us to do it for them. – ADyson Aug 24 '20 at 14:47
  • But... you said "after upload a csv file the concerned php page will open"...my point was why do you need a _different_ PHP page to open? Instead of "importP2.php" and "importP3.php", why not have just "import.php". And then the P2 or P3 value is just one more parameter which you send to import.php, and then it uses that to decide what to do. If you write it like that, then you don't have to worry about changing the form's action. – ADyson Aug 24 '20 at 14:49
  • Ok ADyson, I try to clear your doubt. I have two set's of data table and their field is different if I click on SH named checkbox then importP2,php have to open as importp2.php has specific code for SH table and if I checked DS the after select file concerned php page will open i.e. importP3.php. I think I made clear to you. If any doubt you can asked. Thank you for your patient to look my problem. Also thanks for the reference. – sumanta Aug 24 '20 at 18:05
  • "importp2.php has specific code for SH table and if I checked DS the after select file concerned php page will open i.e. importP3.php"...yes I understand that. But that doesn't mean you actually need two different scripts. You could have one script called "import.php" which contains two different **functions** e.g. `function importP2()` and `function importP3()`. Then you can use a user input value in your form (e.g. make them choose either SH or DS) to allow the user to choose which type of import should run, and then PHP can read that value to decide which function to run. – ADyson Aug 25 '20 at 08:07
  • 1
    Thanks ADyson, for your suggestion. I understood your point and let try to write code such manner. Lets hope which may solve my problem.Thanks again for your suggestion and arrange my code properly. – sumanta Aug 25 '20 at 16:08

0 Answers0