Solved

How do I pass a dynamically created form field to another page through an href query string or on Click method

Posted on 2014-11-26
13
386 Views
Last Modified: 2014-12-16
Hi.  I'm updating an older website that is still using Classic Asp (so please no asp.net answers thanks!)  I'm working with a page where my form fields are dynamically named from a record source.   The user will click on a button or link that will pop up my other page in a new window (specific size) and all i need to know in the new window is what record or row they clicked on.  There are quite a few different ways I see to do this but I'm not sure how to pass my field name variable and value properly within javascript needed to open a new sized pop up window.  For example.. i have ..

<input type="hidden" name="<%=RecFldNm%>" value="<%=vPRecID%>">
<input type="button" name="<%=AddBtn%>"  value="Add">

So..  if I have 3 rows displayed from my record set, I end up with 3 sections on my form with each item named... (source view)

<input type="hidden" name="RecFldNm1" value="39471" >
<input type="button" name="AddBtn1"  value="Add">
<input type="hidden" name="RecFldNm2" value="39472" >
<input type="button" name="AddBtn2"  value="Add">
<input type="hidden" name="RecFldNm3" value="39473" >
<input type="button" name="AddBtn3"  value="Add">

I have no problem getting everything I need when posting the form to my asp code page etc.  My problem here is that I want the user to click on one of the "Add" buttons (or it can be a hyperlink etc.) that opens another page in a new window that is sized that allows them to add some things.  If the user chooses the 2nd record, i want to be able to pass 39472 record id, value of my hidden field RecFldNm2 to the new page or even know that they clicked on AddBtn2.  I can work with either way.. i'm just not sure how to pass the value.

Thanks for any help!
0
Comment
Question by:HometownComp
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40467642
I would do what you are asking via javascript.  You can place asp code in your js code.  But you can also use js and in this sample jquery

<script>
$('[name="RecFldNm1"]').click(function(){
   alert($this.val());
}

</script>

Open in new window

0
 
LVL 18

Expert Comment

by:Greg Alexander
ID: 40467650
I may be over simplifying this but couldn't you pass it in a get variable through and window.open call

<input type="hidden" name="<%=RecFldNm%>" value="<%=vPRecID%>">
<input type="button" name="<%=AddBtn%>"  value="Add" onClick='window.open("http://youdomain.com/page.asp?id=<%=vPRecID%>")'>

Open in new window

0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40467654
jquery was not mentioned, so I'll give you a javascript solution like you asked:

if you're using window.open, you could do something like:

<input type="hidden" name="RecFldNm1" value="39471" >
<input type="button" name="AddBtn1"  value="Add" onclick="window.open( 'popup.asp?fld=' + document.frmName.RevFldNm1.value")

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40467657
Building on that idea, instead of a "pop up" which can be annoying, you can use a modal.  

http://jsmodal.com/docs/usage.php
<!-- load jsmodal.js and jsmodal.css -->

<script>
document.getElementById('modal-1').onclick = function() {
  Modal.open({
    content: '<strong>Default modal!</strong>
              <br />Testing the modal.
              <br /><
              br />Loreum ipsum dolorem the quick brown 
              fox jumped over the lazy dog.
              <br /><br />Yes its true.',
    draggable: true,
    openCallback: function () {
      alert('This is an example of the use of openCallback');
    }
  });
}
</script>

Open in new window


If you like jquery ui http://jqueryui.com/dialog/
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
 
 
</body>

Open in new window

or my favorite bootstrap http://getbootstrap.com/javascript/#modals
<div class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

Open in new window


Using a modal in any of these options allow us to have the data on the page and call it via js or jquery.  A modal gives a nicer experience than a pop up.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40467660
and for more info on window.open, where you can control resizing the window:

http://www.w3schools.com/jsref/met_win_open.asp
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40467744
I also agree with working on the same page via a modal, rather than opening a new window and having to pass all the information to it.

Here is a demo: http://jsbin.com/bafedi/1/edit?html,js,output - click the buttons and you'll see the title changes.  You can work with the passed RecFldNm number.  Only modification is to add the RecFldNm as a data attribute to the button.

		<input type="hidden" name="RecFldNm1" value="39471" />
<button type="button" class="btn btn-primary" name="AddBtn1" data-RecFldNm="39471" data-toggle="modal" data-target="#addRecords">Add</button>
<input type="hidden" name="RecFldNm2" value="39472" />
<button type="button" class="btn btn-primary" name="AddBtn2" data-RecFldNm="39472" data-toggle="modal" data-target="#addRecords">Add</button>
<input type="hidden" name="RecFldNm3" value="39473" />
<button type="button" class="btn btn-primary" name="AddBtn3" data-RecFldNm="39473" data-toggle="modal" data-target="#addRecords">Add</button>

Open in new window


With the javascript, all I have it doing it modifying the title of the modal but you have access to the passed id so you could do anything you wanted with it:
$(function() {	
		$('#addRecords').on('show.bs.modal', function (e) {
		var recfldnm = $(e.relatedTarget).data('recfldnm');
			$('.modal-title').text('Please update for '+recfldnm);
	});
});

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40467762
This is how a more modern approach would be.  You can just as easily use the pure js approach as in my first example but jquery can make it easy.

Using your rendered code as an example with jquery ui.  It can look like this.  I used buttons instead of input type=button and notice I have the id in an attribute called data-rec.  We will use ajax to populate the modal.  The basic example without ajax is below.  A working example http://jsbin.com/puroqisiti/1/edit?html,output
<!DOCTYPE html>
<html>
<head>
 
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
  
  <script>
  $(function() {
    $( "#dialog" ).hide();
    $('.open').click(function(){
       $( "#dialog" ).dialog();
    });
  });
  </script>
  <meta charset="utf-8">
  <title>JS Bin</title>

</head>
<body>

 <!--<input type="hidden" name="RecFldNm1" value="39471" >
<input type="button" class="open" name="AddBtn1"  value="Add">
<!--<input type="hidden" name="RecFldNm2" value="39472" >
<input type="button" name="AddBtn2"  value="Add">
<!--<input type="hidden" name="RecFldNm3" value="39473" >
<input type="button" name="AddBtn3"  value="Add">-->
  
  <button class="open" data-rec="39471">Add 39471</button>
  <button class="open" data-rec="39472">Add 39472</button>
  <button class="open" data-rec="39473">Add 39473</button>
 <div id="dialog" title="Basic dialog"> 
   <p>Your ajax response will go here</p>
</div>
</body>
</html>

Open in new window

The next step is to create a blank asp page than can accept a post or get and output the needed data.  Then via ajax the content from that page will appear in the #dialog.  Example next.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40467764
Rob beat me to it.  That is a big 10-4 +1 good buddy.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40467780
On your ajax page, let say you have a simple response to a post with field name id.

<%
response.write "You selected "&request.form("id")
%>

Open in new window

Then your main page will look like this
<!DOCTYPE html>
<html>
<head>
 
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
  
  <script>
  $(function() {
    $("#dialog").hide();
    $('.open').click(function() {
        //GET THE ID TO  PASS FROM THE ATTRIBUTE DATA-REC
        myID = $(this).attr('data-rec');
        //SET UP THE POST TO YOUR AJAX PAGE
        $.ajax({
                type: "POST",
                url: "the_ajax_page.asp",
                data: {
                    id: myID
                }
            })
            .done(function(data) {
                $("#dialog").html(data); //PLACE THE RESPONSE TO THE #dialog 
                $("#dialog").dialog(); // OPEN THE DIALOG
            });


    });
});
  </script>
  <meta charset="utf-8">
  <title>JS Bin</title>

</head>
<body>

 <!--<input type="hidden" name="RecFldNm1" value="39471" >
<input type="button" class="open" name="AddBtn1"  value="Add">
<!--<input type="hidden" name="RecFldNm2" value="39472" >
<input type="button" name="AddBtn2"  value="Add">
<!--<input type="hidden" name="RecFldNm3" value="39473" >
<input type="button" name="AddBtn3"  value="Add">-->
  
  <button class="open" data-rec="39471">Add 39471</button>
  <button class="open" data-rec="39472">Add 39472</button>
  <button class="open" data-rec="39473">Add 39473</button>
 <div id="dialog" title="Basic dialog"> 
   <!-- no content on the page -->
</div>
</body>
</html>

Open in new window

0
 

Author Comment

by:HometownComp
ID: 40467897
some really good ideas here .. i will check each out very soon...   meanwhile...

I do think it should be simple as Greg Alexander shows but I tried this before and it works except I can't get the new window to size ..  I tried to add it like this..

<input type="hidden" name="<%=RecFldNm%>" value="<%=vPRecID%>">
<input type="button" name="<%=AddBtn%>"  value="Add" OnClick='window.open("http://youdomain.com/page.asp?id=<%=vPRecID%>","width=600, height=400")'>

I get the value and a new window but it is full size.. does anyone see what's wrong?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40467944
I understand but when you say simple, many times what is simple for the end user takes longer to code and this is one of those times.  

Using a pop up like this is pretty rare anymore and you will run into browsers not allowing pop ups unless the user specifically white lists it.
0
 

Author Closing Comment

by:HometownComp
ID: 40503189
Thank you all for your help.   Our client did not want the dialog box, we ended up opening another window (full screen) and showing the previous page's choices listed.   I'm sorry it took a while for me to accept the answer but was forced to spend more time on other work and didn't have time to try these solutions right away.  This post was never abandoned.   The dialog box code will be very useful in the future.  Thanks again.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40503205
if you went with opening another window full screen, then shouldn't this answer be the accepted answer? or at least a split? or did you just use a href link to open a new window?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question