We help IT Professionals succeed at work.

checkbox and form question

adit_2k
adit_2k asked
on
Medium Priority
278 Views
Last Modified: 2008-03-17
hi

I have a dynamically created form, which has items listed according to search done by the user, and against each item , there is a checkbox to add an item in a database

What I want, is as soon as a checkbox is selected for any item, a small pop up window opens, (asp page with some values in querystring), which has details of that particular item, and the user has to click a button in this small pop-up window to add that item. (I will manage this part of displaying information in the pop up)

Incase, he closes the pop-up window, the checkbox is cleared automatically in the main screen, and nothing happens.

Is this possible.
please comment

adit
Comment
Watch Question

Commented:
Somehow you need to know which checkbox it was that has been clicked. You also need to know whether the user has closed the window after or before he actually added the item.

Add the following code to the page:
<script>
function openwindow(fObj)
{
   if(!fObj.checked) return;
   var w = window.open("theasppage.asp", "");
   w.navigator.chObject = fObj;
}
</script>

Make each checkbox like the following:
<input type=checkbox onCLick="openwindow(this)">

Now add the following code to the "theasppage.asp"
<script>
var ActionTaken = false;
function document_onunload()
{
   if(ActionTaken) return;
   navigator.chObject.checked=false;
}
</script>

If the user has takebn some action on "theasppage.asp", you need to set the global variable to true! Like:
<input type=button onClick="ActionTaken=true" value="Do some action">

Regards,
CJ

Commented:
Yes your requirement can be done easily,


Javascript/JS script function :

popupwindow(formname,checkboxname,itemcode)
{
//new window open funciton
window.open("somefine.asp?fname=formname&checkname=checkboxname&itemcode=itemcode
}



When pop window opens, get the query string values and store it in a client side variable.

in the close event of the window
write the following statement

window.opener.formname.checkboxname.checked = false;


I hope it will helps u.
If u can't proceed i can send the function information in detail.

Best of luck


CERTIFIED EXPERT

Commented:
I would use window.ShowModalDialog() to open the popup. That way the user can't mess with the main window while the popup is open, and you easily see what way it was closed.

Something like:

<script>

function GetField(check,hidden)
{
     check.checked=true;
     var field=window.showModalDialog('dialog.asp',hidden.value,'scroll:0');
     if (field!=null) {
          hidden.value=field;
          check.checked=true;
     } else {
          hidden.value='';
          check.checked=false;
     }
}

</script>

<input type="checkbox" onclick="GetField(this,document.all.newField);">
<input type="hidden" id="newField">

---dialog.asp---

<body onLoad="document.all.newField.value=window.dialogArguments">

<input type="text" id="newField">
<input type="button" onClick="window.returnValue=document.all.newField.value;window.close();">

</body>

Author

Commented:
thanks all, i'm trying the options. will take me a day or two.

Will definitely get back

Author

Commented:
I tried everything, thanx, and found CJS's solution, the closest to my need. only problem, here, is that if the pop-up is submitted with button or just closed, the checkbox in the parent window stays as it is. Imean, ideally, if the pop up is closed the corresponding checkbox should also be cleared

GreenGhost also has a ery interesting option to use modal dialog boxes, which I just loved, the only problem, is that any action on an asp page in them opens a new window
and then executed the asp page in this new window

a combi of these 2 will just suit me fine. pls suggest, and i'll distribute/inc the points
CERTIFIED EXPERT

Commented:
Yes, you cannot post a form in a modal dialog, but there is a workaround for that. You use a page with one frame in the dialog, in the frame you can post a form:

<frameset>
<frame src="dialog.asp">
</frameset>

Remember that then you have to use parent.dialogArguments and parent.returnValue to access the input and output of the dialog.

Author

Commented:
thanx, only one problem...

The check box is not clearing if the pop up window is just closed without any action taken.

See if you can help in this regard
CERTIFIED EXPERT

Commented:
My code clears the checkbox if the popup is just closed.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.