如果为空,则在HTML表单上设置默认字段值

时间:2022-11-12 12:14:50

I'm editing Dotmailer's signup form code as some of my users won't have email addresses. I want to set the form so that if the user does not enter a value for their email address, for it to default to say test@test.com

我正在编辑Dotmailer的注册表单代码,因为我的一些用户没有电子邮件地址。我想设置表单,以便如果用户没有为他们的电子邮件地址输入值,则默认为test@test.com

The field must be filled for it to successfully upload for the Dotmailer DB so I can't just remove it as a required field.

必须填写该字段才能成功上传Dotmailer DB,因此我不能将其作为必填字段删除。

Below is the script at the start of the form which seems to be causing the issues (from my limited knowledge)

下面是表单开头的脚本,似乎导致问题(来自我的有限知识)

    <script language="javascript">// <![CDATA[
function validate_signup(frm) {
    var emailAddress = frm.Email.value;
    var errorString = '';
    if (emailAddress == '' || emailAddress.indexOf('@') == -1) {
        errorString = 'Please enter your email address';
    }



    var isError = false;
    if (errorString.length > 0)
        isError = true;

    if (isError)
        alert(errorString);
    return !isError;
}

// ]]></script>

Ty in advance for any assistance you can provide.

提前为您提供任何帮助。

1 个解决方案

#1


1  

You just need to change

你只需要改变

if (emailAddress == '' || emailAddress.indexOf('@') == -1) { errorString = 'Please enter your email address'; }

if(emailAddress ==''|| emailAddress.indexOf('@')== -1){errorString ='请输入您的电子邮件地址'; }

to

if (emailAddress == '' || emailAddress.indexOf('@') == -1) { var input = document.getElementById('#myInput'); input.value = "test@test.com";
}

if(emailAddress ==''|| emailAddress.indexOf('@')== -1){var input = document.getElementById('#myInput'); input.value =“test@test.com”; }

where #myInput is the id of the email field.

其中#myInput是电子邮件字段的ID。

#1


1  

You just need to change

你只需要改变

if (emailAddress == '' || emailAddress.indexOf('@') == -1) { errorString = 'Please enter your email address'; }

if(emailAddress ==''|| emailAddress.indexOf('@')== -1){errorString ='请输入您的电子邮件地址'; }

to

if (emailAddress == '' || emailAddress.indexOf('@') == -1) { var input = document.getElementById('#myInput'); input.value = "test@test.com";
}

if(emailAddress ==''|| emailAddress.indexOf('@')== -1){var input = document.getElementById('#myInput'); input.value =“test@test.com”; }

where #myInput is the id of the email field.

其中#myInput是电子邮件字段的ID。