Results 1 to 7 of 7

Thread: Altering a script

  1. #1
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Altering a script

    I'm trying to alter a script that verifies entries in a Form2Email.


    The name of one of the fields is 'captcha-text' which stops the verifying script from working ie...
    if (document.message.captcha-text.value == "")


    If I change it to 'captchatext' the verifying script then works fine but the Form2Email script stops working ie...
    if (document.message.captchatext.value == "")


    It's clearly the hyphen within the field name that's the problem and if I change all references to it in the Form2Email script the script stops working so I've got to make the verifying script accept the name 'captcha-text'.

    Anyone any idea how I can make it work?

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    You could try using a hidden input field, ie call the validation field 'captchatext' but have a field <input type="hidden" name="captcha-text" id="captcha-text"> ans set the value of this to that same as 'captchatext'.

    This should pass the variable "captcha-text" to the email processor

  3. #3
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Thanks forum_amnesiac

    I know how to set the value of a hidden field if it's the same value everytime but the captcha-text is entered by the user and is different each time so how would I change the value of the hidden field from the entry field captchatext

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    You could add something like

    Code:
    if (document.message.captchatext.value!=""){
    document.message.captcha-text.value = document.message.captchatext.value;
    }
    into the code you have above, or create a separate function of this that is called before the form is submitted.

  5. #5
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Thanks alot it's put me in the right direction

  6. #6
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    I'm still having problems with that hyphen in a field name

    this works fine...
    Code:
    <input type="text" name="captchatext" size=15 value="" onChange="this.form.captcha2text.value=this.value;">
    and puts the value of field captchatext into a field named captcha2text

    but as soon as I change the field name to captcha-text it stops working ie...
    Code:
    <input type="text" name="captchatext" size=15 value="" onChange="this.form.captcha-text.value=this.value;">
    As anyone any ideas why?

  7. #7
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Sorry my fault, javascript doesn't like hyphenated variables.

    It depends on whether your PHP mailer uses field names or field Id's, if it uses the ID then give the field a name without a hyphen and set the value by the name in javascript.

    Vice versa if it uses the name.

    I can't remember off the top of my head but I think there is a method to refer to a field by it's name or it's Id in javascript

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
  •