将html表单的多个输入值从一个输入字段传递到JavaScript事件函数

时间:2021-12-19 09:50:46

I want to pass two input field value of html form and concatenate them by JavaScript. When I am sending one value and the concat function takes one parameter it is ok. But when sending two value and the concat function takes two parameter it is printing << title.value="Undefined" >> in concat function and is concatenate with user_name. I need to pass the title also from user_name field.

我想传递html表单的两个输入字段值并通过JavaScript连接它们。当我发送一个值并且concat函数采用一个参数时,它是可以的。但是当发送两个值并且concat函数接受两个参数时,它在concat函数中打印<< title.value =“Undefined”>>并且与user_name连接。我还需要从user_name字段传递标题。

   <form  "method="post"action="signup.php">
     <label>Name:</label>
        <input type="text" name="title" id="title" />
      <br/>
        <label>Email:;
       <input type="text" name="user_name" id="user_name" onkeyup="concat(this.value,title.value)" />
    </form>

2 个解决方案

#1


2  

Use this. Give some name and id name to the form and call concat function like below.

用这个。给表单提供一些名称和id名称,并调用concat函数,如下所示。

  <form id="form1" name="form1" "method="post"action="signup.php">
     <label>Name:</label>
        <input type="text" name="title" id="title" />
      <br/>
        <label>Email:;
       <input type="text" name="user_name" id="user_name" onkeyup="concat(this.value, form1.title.value)" />
    </form>

#2


2  

Change title.value to document.getElementById("title").value.

将title.value更改为document.getElementById(“title”)。value。

#1


2  

Use this. Give some name and id name to the form and call concat function like below.

用这个。给表单提供一些名称和id名称,并调用concat函数,如下所示。

  <form id="form1" name="form1" "method="post"action="signup.php">
     <label>Name:</label>
        <input type="text" name="title" id="title" />
      <br/>
        <label>Email:;
       <input type="text" name="user_name" id="user_name" onkeyup="concat(this.value, form1.title.value)" />
    </form>

#2


2  

Change title.value to document.getElementById("title").value.

将title.value更改为document.getElementById(“title”)。value。