Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Modifying data entered in a form field?

    Hi,

    I have a date field in a form, which I can validate using javascript, but I have to be able to allow users to enter 'tbc' into this field.

    I can check for 'tbc' when validating the form, but is there a way i can replace 'tbc' for an actual date before the form gets submitted?

    i.e. can I use javascript to replace a value in a form field once a user has clicked submit?

    Thanks very much,
    al.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    yes, i believ you can. Simply change the value of the textfield in a javascript function

    function change(){
    document.forms[0].texfield_name.value = "your new value here";
    return true;
    }


    in body, in your form tag

    <form onsubmit="return change();">

    i did not test, but i suppose it will works...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Basically the same thing

    <html>

    <head>
    <script language="javascript">
    function change(der){
    if(der.value=="tbc")
    der.value="1/1/1990";
    return true;
    }
    </script>
    </head>
    <body>
    <form onsubmit="return change(this.myfield);">
    <input type="text" name="myfield">
    <input type="submit">
    </form>
    </body>
    </html>

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    the arnyinc script is complete, indeed. Now I can sense the ideea of the script (I did not understand at the very begiining why to change that).

    I think that afranka wants to avoid submitting "four letters words" :-). In this case, you may have a list of those, and insert them in script

    if(der.value=="flw1" || der.value=="flw2"|| der.value=="flw3")
    der.value="beeeeep!LOL";

    so
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks very much for your help!!!

    al.


  •  

    Posting Permissions

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