View Full Version : Altering a script
Burgin
05-25-2009, 11:43 AM
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?
forum_amnesiac
05-25-2009, 02:46 PM
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
Burgin
05-25-2009, 03:37 PM
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
forum_amnesiac
05-26-2009, 08:29 AM
You could add something like
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.
Burgin
05-26-2009, 07:07 PM
Thanks alot it's put me in the right direction
Burgin
05-26-2009, 07:28 PM
I'm still having problems with that hyphen in a field name
this works fine...
<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...
<input type="text" name="captchatext" size=15 value="" onChange="this.form.captcha-text.value=this.value;">
As anyone any ideas why?
forum_amnesiac
05-27-2009, 07:51 AM
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
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.