How to change the action="" of a form?

0

I have a problem and I would like to know if you can give me a hand. I have tried to change my action="" of a form. I have tried a lot of code but I still can not get the result. What attempt to make? the action goes as follows:

<form action="reporteria/mipdf.php" align="right" target="reporte" method="POST" >
          <SELECT name="mes">
          <OPTION>selecciona el mes</OPTION>                               
          <OPTION value="01">ENERO</OPTION>
          <OPTION value="02">FEBRERO</OPTION>
          <OPTION value="03">MARZO</OPTION>...
          <INPUT type="submit" value="buscar">
        </form>

The previous code what it does is that it redirects me to mipdf.php. The issue is that I would like to change the "reporter / mipdf.php" so it contains another value of another select, that is:

<form action="X.php" align="right" target="reporte" method="POST" >
              <SELECT name="tiporeporte">
          <OPTION>Selecciona que pdf quieres</OPTION>
          <OPTION value="reporteria/pdf1.php">MiPDF1</OPTION>
          <OPTION value="reporteria/pdf2.php">MiPDF2</OPTION>
          <OPTION value="reporteria/pdf3.php">MiPDF3</OPTION>
          </SELECT>

If someone was very kind, I would really appreciate it if you would give me a hand! Many thanks before hand!

EDITED: Attach the code.

<!DOCTYPE html>
<?php
	require_once 'validar.php';
?>	
<html lang = "es">
	<head>
		<title>Mipagina</title>
		<meta charset = "utf-8" />
		<meta name = "viewport" content = "width=device-width, initial-scale=1" />
		<link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css" />
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
		<link rel="icon" href="images/logopu.png" type="image/x-icon">
	</head>
	<body>
<?php include_once "menu/header.php";?>
			<div id="contenedor">
			<div id="cargando"></div>
			<div id='contenido' style="margin-top:60px">
			<div>
			  <form action="reportes/mipdf1.php" align="right" target="reporte" method="POST">
			  <SELECT name="tiporeporte">
			  <OPTION>Selecciona que pdf quieres</OPTION>
			  <OPTION value="reporteria/pdf1.php">MiPDF1</OPTION>
			  <OPTION value="reporteria/pdf2.php">MiPDF2</OPTION>
			  <OPTION value="reporteria/pdf3.php">MiPDF3</OPTION>
			  </SELECT>	
			  <SELECT name="mes">
			  <OPTION>Selecciona el mes</OPTION>
			  <OPTION value="01">ENERO</OPTION>
			  <OPTION value="02">FEBRERO</OPTION>
			  <OPTION value="03">MARZO</OPTION>
			  <OPTION value="04">ABRIL</OPTION>
			  <OPTION value="05">MAYO</OPTION>
			  </SELECT>
			<INPUT type="submit" value="ir">
			</form>
			  </div>
   			 <iframe width="83%" height="585" name="reporte" src=""></iframe>
  			</div>
			</div>
<?php include_once "menu/footer.php";?>
	</body>
	<script src = "js/jquery.js"></script>
	<script src = "js/bootstrap.js"></script>
	<script src = "js/login.js"></script>
	<script src = "js/sidebar.js"></script>
    
asked by Christian 07.11.2018 в 05:26
source

1 answer

2

The only thing you have to do is capture the change event of the select that will determine the action of the form, and in that event you make the change.

I'll give you an example:

function changeAction(val){
   $("#form1").attr("action",val);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" action="reporteria/mipdf.php" align="right" target="reporte" method="POST" >
          ...
           ...
 </form>

<SELECT name="tiporeporte" onchange="changeAction(this.value);">
          <OPTION>Selecciona que pdf quieres</OPTION>
          <OPTION value="reporteria/pdf1.php">MiPDF1</OPTION>
          <OPTION value="reporteria/pdf2.php">MiPDF2</OPTION>
          <OPTION value="reporteria/pdf3.php">MiPDF3</OPTION>
          </SELECT>


<button onclick="console.log($('#form1').attr('action'))">Mostrar valor de action</button>
    
answered by 07.11.2018 / 05:36
source