SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Form Question

  1. #1
    ǖber abstrakt's Avatar
    Join Date
    Dec 2001
    Location
    Earth
    Posts
    261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Question

    Here's the situation.

    I have a search form field input that opens the search in a new window.

    When you close the search window and return to the parent window the text you entered for your search stays in the input field, and I would like to know how to have this clear when you submit your search so that when you return to the parent page the text field is clear.

    Hopefully this is understandable.

    Thank you in advance for any help.


  2. #2
    Eat, Sleep, *********! J. Pederson's Avatar
    Join Date
    Sep 2001
    Location
    Wisconsin
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put this in the form tag:

    Code:
    onsubmit="javascript:window.location.reload()"
    James Pederson - Web Design & Development
    phone: 608.243.7898
    e-mail: james@transparentacoustics.com
    websites: clear speaker box | website development madison

  3. #3
    ǖber abstrakt's Avatar
    Join Date
    Dec 2001
    Location
    Earth
    Posts
    261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that doesn't work, but I appreciate it anyway.

    Does anyone else know how to do this ?

    Thank you.


  4. #4
    SitePoint Addict
    Join Date
    Jul 2001
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would something along the lines of...

    OnFocus

    ... in the body tag then have the javascript find the specified form field and enter a clear or space in it?

    Sorry, my javascript is very rusty so I can't help on the specifics, but that sounds like a solution.

    Kinda like...

    OnFocus="document.formname.fieldname.value='';"

    ??

  5. #5
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to put the value in between apostrophes (') and then close the function command with a quote (")

    OnFocus="document.formname.fieldname.value=''"

    That's <body ... OnFocus=(quote)document.formname.fieldname.value=(apostrophe)(apostrophe)(double-quote)>

    You don't have to have anything at all between the apostrophes (the value). You can leave it blank or put a default word/message in if you wish.
    Last edited by Bill Posters; Feb 2, 2002 at 17:44.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  6. #6
    ǖber abstrakt's Avatar
    Join Date
    Dec 2001
    Location
    Earth
    Posts
    261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    J pederson, thank you so much. I really appreciate your help.

    I apologize for the earlier post, as your idea has worked, but I had to modify the code a tiny bit.

    Here's the way I used it within the form tag and it worked.


    Code:
    onSubmit="window.location.reload()"


  7. #7
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have an alternative way of handling this. Probably just to add to the archive of informative posts in sitepointforums.

    Code:
        <script language="JavaScript">
        function updateLog() {
            window.open("about:blank","Window","width=600,height=400,scrollbars=yes");
            document.updateLogForm.submit();
            updateLogForm.version.value = ""
        }
        </script>
    
    
    <form action="XXXXXXX" method="post" name="updateLogForm" target="Window">
    <input type="button" value=" Add " accesskey="s" onClick="updateLog()">
    *Note : this code was taken from a script of my own. And the references were not removed. so...

    Notice this code has a built-in window opener. Once the user clicks on the 'Add' button, it'll open a window, and clear the fields of the form contents.

    Let me explain the code in detail for you to modify to your liking.

    --------------------------

    function updateLog() {
    - notice the reference of updateLog() in the Add button too? If you change updateLog to another name, change it in these 2 references.

    window.open("about:blank","Window","width=600,height=400,scrollbars=yes");
    - the name of the window i'm opening is called 'Window' Not very intuitive, but .. anyways, the reference 'Window' is also found in the <form> code where it specifies the window to load the resulting page. target="Window"

    document.updateLogForm.submit();
    - this is the javascript method of initiating the Form Submit button. Resons for doing this will be explained later. Notice the text 'updateLogForm' ? Thats the name of the form i specified in <form>

    updateLogForm.version.value = ""
    - Notice the 'updateLogForm' text too. 'version' is the name of the text box field. so its something like:
    <input type="text" name="version">

    --------------------------

    Now, I had some time to play with the methods of doing this function and I ended up with the above code. Previously, adding just the code to clear the form field would not work. Because, the script will clear the form field before submitting. So the end result would be empty fields in your form. everything in the above code is manually induced. As show by the javascript code. First, Open a window. Then subit the form content, followed by clearing the fields.

    Hoped I explained it well and didn't make it complex as the method isn't complex at all
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •