Change Form Field Value Prior to submit

Discussion in 'ASP General' started by r0adhog, May 19, 2004.

  1. r0adhog

    r0adhog Guest

    I am trying to do some form validation.
    Is there a way with vb script to change the value of a field
    on a form prior to submit.
    r0adhog, May 19, 2004
    #1
    1. Advertising

  2. r0adhog

    Ray at Guest

    You could do this with client-side script, if you like. But, if you're
    going to change it and you know what you're going to change it to, why not
    do it in the ASP code that processes the form submission? Can you be a
    little more specific about what you're trying to do?

    Ray at work

    "r0adhog" <> wrote in message
    news:...
    > I am trying to do some form validation.
    > Is there a way with vb script to change the value of a field
    > on a form prior to submit.
    >
    >
    >
    Ray at, May 19, 2004
    #2
    1. Advertising

  3. r0adhog

    r0adhog Guest

    Ray/Curt,

    I guess I could do it after the submit, was looking to do something like
    If x = "true" then
    document.MyForm.all("FieldName").value =
    CleanedUp(document.MyForm.all("FieldName").value)
    document.MyForm.summit()
    End If

    Will that work?

    rh

    "r0adhog" <> wrote in message
    news:...
    > I am trying to do some form validation.
    > Is there a way with vb script to change the value of a field
    > on a form prior to submit.
    >
    >
    >
    r0adhog, May 19, 2004
    #3
  4. r0adhog

    Ray at Guest

    Well, this would be the client-side approach, not the ASP approach. As Curt
    suggested, you should not use VBScript for client side scripting. Try
    something like:

    <script type="text/javascript">
    function myFunction(f) {
    // What is x?
    var x = true;
    var v = f.FieldName.value
    if(x) {f.FieldName.value=CleanedUp(v); }
    return true;
    }

    function CleanedUp(s) {
    return 'what should this be?';
    }
    </script>


    <form onsubmit="return myFunction(this);">


    Again, what are you trying to do? You're not doing this to deal with
    apostrophes or anything, I hope, are you?

    Ray at work


    "r0adhog" <> wrote in message
    news:OH%...
    > Ray/Curt,
    >
    > I guess I could do it after the submit, was looking to do something like
    > If x = "true" then
    > document.MyForm.all("FieldName").value =
    > CleanedUp(document.MyForm.all("FieldName").value)
    > document.MyForm.summit()
    > End If
    >
    > Will that work?
    >
    Ray at, May 19, 2004
    #4
  5. r0adhog wrote:
    >
    > I guess I could do it after the submit, was looking to do something
    > like If x = "true" then
    > document.MyForm.all("FieldName").value =
    > CleanedUp(document.MyForm.all("FieldName").value)
    > document.MyForm.summit()
    > End If
    >
    > Will that work?


    It pains me to say, "probably" (except for the misspelled submit() method),
    but it certainly depends on intercepting the submission.

    It pains me for three reasons: (1) VBScript on the client, (2) the use of
    ..all, and (3) referencing a collection with parentheses instead of brackets.
    Internet Explorer lets you get away with all three, but I don't consider
    that a good thing.

    Generally speaking, form element references ought to look like this:

    document.MyForm.elements["FieldName"]

    If you don't use funky characters for naming your fields (and don't collide
    with the FORM element's property/method namespace, you can get away with
    this:

    document.MyForm.FieldName

    Examples that require the former:

    <INPUT NAME="Address(2)"> **
    <INPUT NAME="submit"> ***

    I object to VBScript on the client for religious reasons, FWIW.



    **I've actually seen this!!
    ***Probably one of the most common newbie errors


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, May 19, 2004
    #5
  6. r0adhog

    Ray at Guest

    "Dave Anderson" <> wrote in message
    news:O5%23zW%...
    >
    > I object to VBScript on the client for religious reasons, FWIW.


    This topic doesn't seem to be addressed in my current reading, the Complete
    Idiot's Guide to Understanding Judaism, so I guess it must be some other
    religion.

    Ray at work
    Ray at, May 19, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page