PDA

View Full Version : Multiple actions from single 'onclick'?



Hebbs
06-22-2005, 08:52 AM
This is driving me nuts!

I have a webpage which is a form that requires completion and submission as they do.

I want to check that the required fields have been completed and if all correct proceed with submission of the form.

On submission it goes to a script which generates a PDF file for printing and then should automatically redirect to the home page (quote.php).

I have tried the following at the submit end of the page...



</tr>
<tr bgcolor='$html_table_td_bgcolor' >
<td nowrap align='left'><input type='button' name='back' value='<- Back' onClick='self.history.back();'></td>
<td align='right'><input type='submit' name='submit' value=' Print Delivery Note ' onClick=\"return CheckRequiredFields(); onClick=document.location = './quote.php';return true\" ></td>
</tr>
</form>


and can get either Javascript command to work but not both.

The CheckRequiredFields is a function that does exactly that and works OK alone. I have tried a single comma separating the two but the Javascript error pops up, as it should, but then everything closes and redirects to the quote.php page when you click OK.

Can this be done this way?

Thanks

Hebbs

cr3ative
06-22-2005, 08:59 AM
Just off the top of my head, I can see that this is wrong:


<td align='right'><input type='submit' name='submit' value=' Print Delivery Note ' onClick="return CheckRequiredFields(); onClick=document.location = './quote.php';return true\" ></td>


Try out

<td align='right'><input type='submit' name='submit' value=' Print Delivery Note ' onClick="return CheckRequiredFields();document.location='./quote.php';return true" ></td>

I can't test it right now, I'm afraid, but see if that works.
cr3ative

mwinter
06-22-2005, 10:23 AM
I want to check that the required fields have been completed and if all correct proceed with submission of the form.

On submission it goes to a script which generates a PDF file for printing and then should automatically redirect to the home page (quote.php).


<input type='submit' name='submit' value=' Print Delivery Note ' onClick="return CheckRequiredFields(); onClick=document.location = './quote.php';return true\" >Can this be done this way?No. When the form is submitted, the browser will have to make a request to the server, and at that point the current document is discarded. You cannot use scripts in the first document to cause something to happen after this request is made.

What you need to do is redirect from the URL that this submission goes to. Once it has finished processing, it can return the user to the home page.


onClick="return CheckRequiredFields();document.location='./quote.php';return true">

I can't test it right now, I'm afraid, but see if that works.It won't, for the reasons above. Also, the first return statement would stop any further processing of the listener.

Mike

Hebbs
06-23-2005, 01:04 AM
Thanks guys, I should have posted BEFORE I spent half a day trying to get the thing to work! :(

Havent tried to redirect a page that isnt presented to the browser before, any suggestions (whilst I search the net!) would be most welcome.

Regards

Hebbs

Hebbs
06-23-2005, 02:58 AM
OK,

Ignore my last. Realised my error in thinking here.

What I need to do to make this work is best explained as follows.

I have my parent script/window which is a form. I can check for errors OK and open up a _new window from the form when submitted.

This child window is a pdf form that is for printing and is then closed - no buttons or links.

What I need to happen is this.

1. When child is opened, refresh parent.
2. Have parent detect the refresh (this is where Im stuck :confused: ) then redirect itself - not close.

ANy thoughts?

Hebbs

Twey
06-23-2005, 01:38 PM
You can use target on the submit button.


<input type=submit blah=blah onclick="window.open('quota.php');" target="_blank"/>

I think this is what you meant. You didn't make it very clear. For example, why do you want to refresh the page then redirect it?

Hebbs
06-23-2005, 01:42 PM
Sorry Twey,

Im not sure where you are going with that. I think Ive missed something here.

Hebbs

Twey
06-23-2005, 01:59 PM
OK,

What I need to do to make this work is best explained as follows.

I have my parent script/window which is a form. I can check for errors OK and open up a _new window from the form when submitted.

This child window is a pdf form that is for printing and is then closed - no buttons or links.

What I need to happen is this.

1. When child is opened, refresh parent.
2. Have parent detect the refresh (this is where Im stuck :confused: ) then redirect itself - not close.

ANy thoughts?

Hebbs

As I see it, when the form is submitted, you want to open the PDF script in another window (with variables passed to it), then refresh the first window, then redirect the first window to somewhere else? I was a bit confused by
2. Have parent detect the refresh (this is where Im stuck :confused: ) then redirect itself - not close.
- Why do you want it to refresh then redirect itself? Surely it would be easier just to point it to the page it should be redirected to in the first place?