HometownComp
asked on
How do I pass a dynamically created form field to another page through an href query string or on Click method
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!
<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!
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%>")'>
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:
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")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and for more info on window.open, where you can control resizing the window:
http://www.w3schools.com/jsref/met_win_open.asp
http://www.w3schools.com/jsref/met_win_open.asp
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.
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:
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>
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);
});
});
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
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>
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.
Rob beat me to it. That is a big 10-4 +1 good buddy.
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")
%>
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>
ASKER
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=<%=v PRecID%>", "width=600 , height=400")'>
I get the value and a new window but it is full size.. does anyone see what's wrong?
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=<%=v
I get the value and a new window but it is full size.. does anyone see what's wrong?
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.
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.
ASKER
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.
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?
Open in new window