Results 1 to 8 of 8

Thread: Multiple actions from single 'onclick'?

  1. #1
    Join Date
    Jun 2005
    Location
    Perth, Western Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Multiple actions from single 'onclick'?

    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...

    PHP Code:
    </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

  2. #2
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Hebbs
    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).

    Code:
    <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.

    Quote Originally Posted by cr3ative
    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

  4. #4
    Join Date
    Jun 2005
    Location
    Perth, Western Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  5. #5
    Join Date
    Jun 2005
    Location
    Perth, Western Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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 ) then redirect itself - not close.

    ANy thoughts?

    Hebbs

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can use target on the submit button.

    HTML Code:
    <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?
    Last edited by Twey; 06-23-2005 at 01:54 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2005
    Location
    Perth, Western Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry Twey,

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

    Hebbs

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by Hebbs
    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 ) 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
    Quote Originally Posted by Hebbs
    2. Have parent detect the refresh (this is where Im stuck ) 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?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •