popup updates parent

whargra
whargra used Ask the Experts™
on
I'm wanting to open a popup window, save some value, then when saved have a select box value change on the parent window without refreshing the parent window.

Here is what I have on the child window:
<Script LANGUAGE="JavaScript">
<!--
function setIt() {
     if (document.formname.inputbox.value > "0")
          {
window.opener.document.formname.selectbox.value = "Y";
}
}
//-->
</script>

<input type="text" name="inputbox" class="txt" value="<%=(rsRecord.Fields.Item("PayRate").Value)%>">

<input type="submit" name="btnUpdate" value="Save" onClick="setIt();" class="sbttn"()">

Now the Save button doesn't close this child window because there may be more values added, so there is a close button that actually closes this child.

In the parent window I have a hidden input just before the vbscript that calls the select box:
<INPUT TYPE=hidden NAME="selectbox" VALUE="">

As this is, nothing happens and there are no errors generated. What am I missing and can this select box value be changed from the child without refreshing the parent?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Michel PlungjanIT Expert
Top Expert 2009

Commented:
change
<input type="submit" name="btnUpdate" value="Save" onClick="setIt();" class="sbttn"()">

to

<input type="button" name="btnUpdate" value="Save" onClick="setIt();" class="sbttn">

 

Author

Commented:
Changing the input type didn't work, I also tried onSubmit instead of onClick.

Commented:
the condition you are checking seems to be very weird:
if (document.formname.inputbox.value > "0")


if you want to compare the content of that field, use rather this:

if (parseInt(document.formname.inputbox.value)>0) then everything should be ok....In fact, I guess your test never gives us a true!

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

try this in the if...

if(document.formname.inputbox.value != "")


that should check if the inputbox has anything in it. if it does, it'll go about saving it.

Author

Commented:
Just remembered the parent window is in a frame, how would this change the window.opener script?

Commented:
Doesn't matter...

if you have the frame name of the window parent, just do the following (again, assuming you are comparing an integer value, otherwise, just the "if condition"):

if (parseInt(document.formname.inputbox.value)>0){
window.opener.parent.frames["yourframename"].document.formname.selectbox.value = "Y";
}
 
just replace the yourframename by the name your parent window is in....

Commented:
What do you mean by:

>  In the parent window I have a hidden input just before >  the vbscript that calls the select box:
>  <INPUT TYPE=hidden NAME="selectbox" VALUE="">

It seems like the code in the child window is only changing this hidden field.  What code is responsible for changing the select itself?  What makes that code run?  If it's an onchange event, changing the value of the hidden field programmatically will not fire the onchange event.

Author

Commented:
Yes, there is an onChange for the select box and an onClick event for a link that opens the same popup.

I have the onChange working ok because you select the Yes, the popup happens and when you save and return the Yes value is still there.

The problem is when using the link. What I want is when a user clicks the link to open the popup, saves info in the popup and returns to the parent window that the selectbox value will change accordingly. But I don't want the parent page to refresh cause there are other values there.

I use 0 as the inputbox value on the popup to decide if the selectbox should be Y or N. If 0 or no value entered then N if something is entered then Y.

Author

Commented:
Ok, here is the latest attempt, I'm out of things to try on this.

function setIt() {
if (parseInt(document.formname.inputbox.value) > 0) {
window.opener.document.formname.selectbox.selectedIndex=0;
}
}

Commented:
I'm a little confused by what you're trying to do...you've showed us the code from the child window, but what does the parent look like?

I still see the problem as follows:

Parent page has hidden field called selectbox.
Parent page has a select called idontknow.

Event occurs on child page.  Child page updates SELECTBOX, which is a hidden field.

idontknow is never going to change because you haven't touched it...you've only changed the hidden field.

Have I described your situation?

Author

Commented:
Yes but I dumped the hidden field cause like you said it is a select box not a text box. I have to figure someway of changing the selectbox on the parent from the child.

The problem stems from the fact that the popup is opened from the parent by a link instead of the selectbox. But if a value is changed on the popup, I need the selectbox (yes/no) to change when the popup is closed without refreshing the parent window.
Commented:
I feel like there must be something simple missing.  I did the following:


This is the child page ... child1.asp

<Script LANGUAGE="JavaScript">
<!--
function setIt() {
     if (parseInt(document.forms[0].inputbox.value) > 0) {
          window.opener.document.forms[0].selectbox.selectedIndex=0;
     }
}
//-->
</script>
<form>
<input type="text" name="inputbox" class="txt" value="100">

<input type="submit" name="btnUpdate" value="Save" onClick="setIt();">
</form>

This is the parent page parent1.asp:


<script language="javascript">
     function openIt(){
          window.open("child1.asp");
     }
</script>
<form>
<select name="selectbox">
     <option value="Y">Yes</option>
     <option value="N" selected>No</option>
</select>
<input type="button" onclick="openIt();">
</form>


This works.

Author

Commented:
Does this keep the parent page from refreshing?

Commented:
Yes.  It just changes the select.

Author

Commented:
Ok, I'm just goning to post all the involved code and maybe someone can see what I'm missing.

Parent window:
<td>
<span id="tier">
<%
Dim vPayCode, vPayGroup
  vPayCode = Trim(rsSVCMaster("PayTypeCode"))
  vPayGroup = Trim(rsSvcMaster("SVM_Group"))
 'Response.Write vPayCode
 Select Case vPayGroup
 Case "Inpatient"
  'If (vPayCode = "CR") or (vPayCode = "PD") Then
  'Response.Write vPayCode
  Response.Write("<a href='#' onClick='openPay()' onMouseOver='window.status=""Per Diem/Per Case Window""; return true' onMouseout='window.status=""""; return true' onFocus='if(this.blur)this.blur()'>Tiered Payment:</a> </font>")
  Response.Write ("<font face='Arial, Helvetica, sans-serif' size='1'> <select name='Tiered' class='drpdwn' onChange='openOPayWindow()'>")
  Response.Write("<option>")
    If rsSVCMaster("SVM_PayRate1") > "0" Then
  Response.Write("Yes")
    ElseIf rsSVCMaster("SVM_PayRate1") <= "0" Then
  Response.Write("No")
 End If
  Response.Write("</option>")
  Response.Write("<option value='Y'>Yes</option>")
  Response.Write("<option value='N'>No</option>")
  Response.Write("</select>")
   'Else
   'Response.Write("")
   'End If
 Case Else
  Response.Write("")
 End Select
%>
</span></td>


Child window:
<Script LANGUAGE="JavaScript">
<!--
function setTier() {
 if (parseInt(document.forms.Add_Payment.PayRate1.value) > 0) {
window.opener.document.forms.catSummary.Tiered.selectedIndex=0;
   }
 else {
window.opener.document.forms.catSummary.Tiered.selectedIndex=1;
   }
}
//-->
</script>

and in the body to fire the script:

<input type="submit" name="btnUpdate" value="Save" class="sbttn" onClick="setTier();" onMouseOver="window.status='Save'; return true" onMouseout="window.status=''; return true" onFocus="if(this.blur)this.blur()">

Author

Commented:
Well, I decided to reverse the process, I placed a script to capture the value on the child page of the input box,. And then had a script fire on the parent to look at the value and then change the select box to yes/no.

Author

Commented:
Wasn't quite it for my situation but still a very good answer and thanks for the efforts.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial