1

here is the BUTTON from the index.php to open the Modal form;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<a href="#myModal" data-toggle="modal" value="#01" name="btn" class="button2 btn btn-success model_open" data-btnval = "#01" aria-hidden="true" data-dismiss="modal" >form</a>

this is the script to get the value of the current button;

$(document).on("click", ".model_open", function () {
var btnval = $(this).data('btnval'); 

   $(".modal-body #btnval").text( btnval );
$('#hiddenid').val(btnval );
});

and this is the Modal Form echoing the button value "#01"

<!-- Modal header starts -->                                                
                    <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
                          <div class="modal-dialog">
                              <div class="modal-content">
                                  <div class="modal-header1" style="padding:10px 15px;">
                                <button type="button" class="close" data-dismiss="modal" >&times;</button>
                                    <h4><span class="glyphicon glyphicon-pencil"></span>MODAL FORM</h4>
                            </div>
                                <div class="modal-body" style="padding:10px 10px;">
<!-- Modal header ends -->

            <div id="btnval"></div> <!-- Echo the button value "#01" -->

<!-- Modal Application form starts -->  
                 <div class="modal-body">

                        <div class="modal-body">
                        <form action="confirmation.php" method="get" enctype="multipart/form-data">

                    <!-- First Name Filed Starts -->
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label for="name">NAME</label>
                                <input type="text" class="form-control" name="name" id="name" required="required" placeholder="Name">
                            </div>
                        </div>

            <input type="submit" class="btn btn-success pull-right" value="NEXT">

when click NEXT button in the Modal Form, it will proceed to the 2nd page to dsiplay all of the information from Modal form together with the button value "#01";

<form id="main-contact-form1"  style="background-color: #f0f8ff; padding: 20px;" class="contact-form1" name="contact-form1" method="post" action="sendappli.php" role="form">   


                      <div class="label-field-pair">
                        <label>ID</label>
                        <input class="form-control" id='id' name='id' value='<?php echo $_GET["btnval"]; ?>'  />
                      </div>

          <div class="label-field-pair">
                        <label>Name</label>
                        <input class="form-control" id='name' name='name' value='<?php echo $_GET["name"]; ?>'  />
                      </div>

checking the provided information before it will send to my email address.

problem: I can't get the value of "btnval" from <div id="btnval"> that need to have a NAME to get its value and echoing it to <?php echo $GET[posible name of btnval];?/> at the 2nd page????

enter image description here

Marvin Acosta
  • 168
  • 10

4 Answers4

2

see the below code

var div= document.getElementById('btnval');
div.setAttribute('name', 'sample');

or:

document.getElementsByTagName("DIV")[0].setAttribute("name", "sample");
sumit chauhan
  • 1,270
  • 1
  • 13
  • 18
0

use load method to get div from first page to second page

$("#div").load("/firstpage.html #btnval");

load div using its id on second page

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
  • hello @Bhargav thank you for your time, I tied your code but I got an error --> Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$ – Marvin Acosta Nov 03 '17 at 01:43
0

You can use data attributes instead.

<div id="btnval" data-name="sample">

Then you can pass it to another page as a url parameter using jquery and then get it using,

<?php echo $_GET["sample"]; ?>
0

try this code,

1) index.php

<div id="btnval">Hello This My Div</div>

<script type="text/javascript">
    var div = document.getElementById('btnval');
    div.setAttribute('name', 'sample');
</script>

2) demo.php

<?php
include 'index.php'; // include your other files
?>
<script type="text/javascript">
    console.log(document.getElementById('btnval').innerHTML);
    var div = document.getElementById('btnval');
    console.log(div.getAttribute('name'));
</script>
krupal parsana
  • 132
  • 1
  • 9
  • hello, @Krupal thank you for the code, but my
    is the ECHO value button from the index.php which I echoed on the Modal Form using javascript. all code is perfectly well processed. I just like to put a name inside the
    to get the value of this id "btnval" and echoing it to the 2nd page.
    – Marvin Acosta Nov 03 '17 at 01:51