Passing variable from a link to a form

Hi I want to pass a variable from a link to a pop up form on the same page i have tried evey way i can think but still no joy, can someone help me with this please.
--------------HERE IS MY CODE ----------------------------------
The link is at the bottom of the form named Calculation

 <form form role="form" class"box"name="paymentIDForm" method="post" id="my_form"action="pay.php?amount=<?php echo $row['price']; ?>&fee=<?php echo $row['maintanancefee']; ?>&title=<?php echo $row['title']; ?>&description=<?php echo $row['description']; ?>&speed=<?php echo $row['speed']; ?>"> 
                 <input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
                 <input type="hidden" name="fee" value="<?php echo $row['maintanancefee']; ?>">
                 <input type="hidden" name="title" value="<?php echo $row['title']; ?>">
                 <input type="hidden" name="description" value="<?php echo $row['description']; ?>">
                 <input type="hidden" name="speed" value="<?php echo $row['speed']; ?>">
                    <div class="pricingTable-header">
                        <h3 class="title"><?php echo $row['minecoin']; ?></h3>
                        <span class="price-value">
                           $<?php echo $row['price']; ?>
                        </span>
                    </div>
                    <ul class="pricing-content">
                        <li><?php echo $row['description']; ?></li>
                        <li>Get <?php echo $row['profitperday']; ?> BTC Per Day</li>
                        <li><?php echo $row['maintanancefee']; ?></li>
                        <li><?php echo $row['speed']; ?> Daily</li>
                        <li>period <?php echo $row['period1']; ?> <?php echo $row['period']; ?></li>
                    </ul>
                    
                <input name="m_process" type="submit" class="btn btn-primary" value="Continue to payment">
            <?php           
         
		  ?>
 </form><hr><a data-toggle="modal" href="main.html?amount=<?php echo $row['price']; ?>#myModal70" class="btn btn-default side">Calculation</a>

 </div>
            </div>
<?php }?>

</div>

------------AND THE POP UP BOX---------------------------------------

I want the variable to output in the input field name=“txtcalcourm”

<!-------------------------------------------------------------Bitcoin Calculator ---------------------------------------------------------->


 <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal70" class="modal fade">
		              <div class="modal-dialog">
		                  <div class="modal-content" Style="background: #371d1d;">
		                      <div class="modal-header">
		                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                          <h3 class="modal-title" Style=" color: #FFFFFF;">Profitability</h3>
		                      </div>
		                      <div class="modal-body">
                              
         <form class="frmMHS" name="frmMHS" id= "frmMHS" method="post" action="">
               <input type="text" id="mhsdoge" name="mhsdoge" value="1.63934426" hidden="hidden" />
                <input type="text" id="mhscost" name="mhscost" value="0.00000100" hidden="hidden" />
                <input type="text" id="mhscostusd" name="mhscostusd" value="1.00" hidden="hidden" />
                </form>
                                         <div class="content">
	           

                 
	            <div class="container-fluid">
	                <div class="row">
	                    <div class="col-md-12">
	                        <div class="card">
	                            <div class="card-header" data-background-color="blue">
	                              <h4 class="title">Calculator of profitableness MH/s</h4>
	                                <p class="category" Style="color: #FFFFFF; font-size: medium;">Enter the desired power in the box below</p>
	                            </div>
                                <?php 
								
                                $price = $_GET['amount'];
								?>
                                
                                <form class="frmPriceM" name="frmPriceM" id= "frmPriceM" method="post" action="">
                                            <div align="center"><input type="text" class="form-control" id="txtcalcourm" name="txtcalcourm" value="<?php echo $price; ?>" onFocus="GetPriceMHS(); Ftest (this)"
      /> </div>
	                            <div class="card-content table-responsive">
	                                <table class="table">
	                                    <thead class="text-primary">
                                             <th></th>
	                                    	<th>Per day</th>
	                                    	<th>Per month</th>
	                                    	<th>Per year</th>
											<th>Per two years</th>
	                                    </thead>
	                                    <tbody style="color:white;">
	                                        <tr><td>Bitcoin</td>
	                                        	<td><div  id="MhsdayB">0.00000000</div></td>
	                                        	<td><div  id="MhsmonthB">0.00000000</div></td>
	                                        	<td><div  id="MhsyearB">0.00000000</div></td>
												<td><div  id="MhstwoB">0.00000000</div></td>
	                                        </tr>
	                                        <tr><td>Inr</td>
	                                            <td><div  id="MhsdayD">0.00000000</div></td>
	                                        	<td><div  id="MhsmonthD">0.00000000</div></td>
	                                        	<td><div  id="MhsyearD">0.00000000</div></td>
												<td><div  id="MhstwoD">0.00000000</div></td>
	                                        </tr>
	                                        <tr><td>Usd</td>
	                                            <td><div  id="MhsdayU">0.00</div></td>
	                                        	<td><div  id="MhsmonthU">0.00</div></td>
	                                        	<td><div  id="MhsyearU">0.00</div></td>
												<td><div  id="MhstwoU">0.00</div></td>
	                                        </tr>
	                                    </tbody>
	                                </table>

	                            </div>
                                </form>
	                        </div>
	                    </div>
	                </div>
	            </div>
	        </div>

<!---------------------------------------------------------- End Bbitcoin calculato------------------------------------------------------------->
                                  

tthankyou

Then that would be a matter of JS rather than PHP… assuming you have something like this to show the modal:

var modalToggle = document.querySelector('[data-toggle="modal"]')

modalToggle.addEventListener('click', function (event) {  
  var modal = document.querySelector(event.target.hash)
  
  event.preventDefault()
  modal.style.display = 'block'
})

… then you can get the URLSearchParams of the link being clicked like so:

modalToggle.addEventListener('click', function (event) {  
  var modal = document.querySelector(event.target.hash)
  var txtcalcourm = modal.querySelector('[name="txtcalcourm"]')

  // Create an URLSearchParams object from the event target's
  // query string, and then get the amount value
  var params = new URLSearchParams(event.target.search)
  var amount = params.get('amount')
  
  event.preventDefault()

  txtcalcourm = amount
  modal.style.display = 'block'
})

BTW shall I move this topic to the JS category for further discussion?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.