...

View Full Version : How to pass the checkbox values when opening a new window



jenab
01-18-2006, 01:32 AM
I have a form that has checkboxes and I need to open a new window and pass the value of the checkboxes in the url as a parameter. My next page is an asp page that looks for the value in the querystring for the SQL query on that page.

Currently my code to open the new window looks like this, this is an .asp page:

<A HREF="show_line_items.asp?id=<%ID%>" ONCLICK="window.open('show_line_items.asp?ID=<%=id%>'); return false">View Line Items</a>

I need to add the values from chk_SOID the resulting url needs to look like this - http://mysite.com/show_line_items.asp?ID=1&SOID=whateverthevalueof_chk_SOID is equal to.

I have no idea how to do this. I have scoured the web and I can't find an example of how to do, couldn't find anything in any of my javascript books. Figured this would be easy for someone with a lot of Javascript experience. My Javascript is limited to what I can copy and make small modifications to. If anyone can point me to an example or provide one I would greatly appreciate it.

glenngv
01-18-2006, 03:59 AM
<A HREF="show_line_items.asp?id=<%ID%>" ONCLICK="return doOpen('show_line_items.asp', '<%=id%>');">View Line Items</a>
...
function doOpen(page, id){
var w = window.open(page + '?id=' + id + '&SOID=' + document.forms[0].chk_SOID.value, "lineItemsWin", "width=600, height=400, resizable=1");
w.focus();
return false;
}

or I think you want to pass the value of the checkbox only if it's checked.

function doOpen(page, id){
var soid = (document.forms[0].chk_SOID.checked) ? document.forms[0].chk_SOID.value : "";
var w = window.open(page + '?id=' + id + '&SOID=' + soid, "lineItemsWin", "width=600, height=400, resizable=1");
w.focus();
return false;
}

jenab
01-18-2006, 05:02 PM
I tried this code and it is still only passing the ID and not adding the SOID=andwhateverischecked to the url. It is not even adding the &SOID=, the url looks like this: http://mysite.com/show_line_items.asp?id=1-120674099. It is opening a new window.

konithomimo
01-18-2006, 08:46 PM
This will work for any number of checkboxes:


function sendIt(page,id)
{
var myform = document.getElementsByTagName('form')[0]; //first form on page

var inputs = myform.getElementsByTagName('input');
var i;

for(i=0;i<inputs.length;i++)
{
if((inputs[i].type == 'checkbox') && (inputs[i].checked == true))
{
var soid = page + '?id=' + id + '&SOID=' + inputs[i].value;
var w = window.open(soid, "lineItemsWin", "width=600, height=400, resizable=1");
w.focus();
return false;
}
}
}

jenab
01-18-2006, 10:29 PM
Here is the line that calls the function:

<TD bgcolor=<%=str_BgColor%>><A HREF="quote_header_info.asp?id=<%=ID%>" ONCLICK="return sendIt('quote_header_info.asp', '<%=ID%>');">Go</a></td>

It does not open a new page, it looks like it just sending it to the url in the A HREF tag. It looks like this: http://mysite.com/testing/quote_header_info.asp?id=1-124689347

For some reason the url does not display correctly the text after testing is /quote_header_info.asp?id=1-124689347

And the script you so kindly posted:
<script Language="JavaScript">
<!--

function sendIt(page,id)
{
var myform = document.getElementsByTagName('form')[0]; //first form on page

var inputs = myform.getElementsByTagName('input');
var i;

for(i=0;i<inputs.length;i++)
{
if((inputs[i].type == 'checkbox') && (inputs[i].checked == true))
{
var soid = page + '?id=' + id + '&SOID=' + inputs[i].value;
var w = window.open(soid, "lineItemsWin", "width=600, height=400, resizable=1");
w.focus();
return false;
}
}
}
//-->
</script>

glenngv
01-19-2006, 02:23 AM
The page might have javascript errors as it loads causing subsequent function calls or statements not to work. Check the Javascript Console after the page loads to see if there's any error.

jenab
01-19-2006, 08:07 PM
I loaded the page and there is no error icon showing.

Does the code look right? Does the syntax look right? I am thinking it is probably one little thing throwing the whole thing off.:confused:

glenngv
01-20-2006, 03:39 AM
Put an alert inside the function to verify that it is being called at all.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum