简体   繁体   English

通过上一个输入框的onClick功能使输入字段可见仅工作一次

[英]Making input field visible by the onClick function of the previous input box only works once

I've built a form that has 16 input boxes for the user to type in a list of characteristics. 我建立了一个具有16个输入框的表单,供用户键入特征列表。

Now, I'm trying to make it so when you click in one of the text fields to type, the next field appears. 现在,我试图做到这一点,因此当您单击文本字段之一进行键入时,将显示下一个字段。

It works to make the 2nd box appear and that's all. 它可以使第二个框出现,仅此而已。

I used a for next loop to do this. 我使用了一个for next循环来做到这一点。 Below is the code, why won't it work for any consecutive boxes following the 2nd one? 下面是代码,为什么它对第二个框之后的任何连续框都不起作用?

1) <input type="text" name="objective1" size="50" onClick="document.getElementById('obj2').style.display='inline';" /><br />

<%

Dim i, b
b = 0

For i = 2 To 16
   b = i+1
   Response.Write("<span id='obj" & i & "' style='display:none'>")
   Response.write(i & ") <input type='text' name='objective" & i & "' size='50' onClick='document.getElementById('obj" & b & "').style.display='inline';' /><br />")
   Response.Write("</span>")
Next

%>

I'm developing this at/for work, and we are using IE8, so keep that in mind for function capabilities. 我在工作中/在工作中正在开发此功能,而我们正在使用IE8,因此请记住函数功能。

Any input would be great. 任何输入都会很棒。 I think this code makes sense...? 我认为这段代码有意义...? It's probably missing a minor piece of code that I'll feel dumb for not realizing lol. 它可能会丢失一小段代码,因为我没有意识到哈哈,我会觉得很愚蠢。

Thank you 谢谢

** SOLUTION: ** **解决方案:**

I fixed the problem. 我解决了这个问题。 It was an issue with the quotations, like @John and @Vlad mentioned. 报价出现问题,例如提到的@John和@Vlad。

Except his proposed solution code gave me a syntax error so I had to take a different approach: 除了他提出的解决方案代码给了我一个语法错误,所以我不得不采取另一种方法:

Response.write(i & ") ") %><input type="text" name="objective<%=i%>" size="50" onClick="document.getElementById('obj<%=b%>').style.display='inline';" /><br /><%

I fixed the above line in the For Next loop. 我在For Next循环中修复了上面的行。

OR as @Martyn0627 submitted: 或@ Martyn0627提交:

Response.write(i & ") <input type='text' name='objective" & i & "' size='50' onClick=""document.getElementById('obj" & b & "').style.display='inline';"" /><br />")

Thanks for the help guys! 感谢您的帮助!

You have quotes problem in the onclick attribute: 您在onclick属性中存在引号问题:

<input 
type='text' 
name='objective" & i & "' 
size='50' 
onClick='document.getElementById('obj" & b & "').style.display='inline';'  <~~~ HERE
/>

Try escaping them (replace single quotes that surround the onclick attribute value with double quotes): 尝试转义它们(用双引号替换包围onclick属性值的单引号):

Response.write(i & ") <input type='text' name='objective" & i & "' size='50' onClick=""document.getElementById('obj" & b & "').style.display='inline';"" /><br />")

Use double double quotes in an ASP response.write statement when you want double quotes in your output. 如果要在输出中使用双引号,请在ASP response.write语句中使用双引号。

Response.write(i & ") <input type=""text"" name=""objective" & i & """ size=""50"" onClick=""document.getElementById('obj" & b & "').style.display='inline';"" /><br />")

Edit - My entire page, which I've tested 编辑-我已测试的整个页面

<html>
<head>
<title> New Document </title>

</head>

<body>
1) <input type="text" name="objective1" size="50" onClick="document.getElementById('obj2').style.display='inline';" /><br />

<%

Dim i, b
b = 0

For i = 2 To 16
b = i+1
Response.Write("<span id=""obj" & i & """ style=""display:none"">")
Response.write(i & ") <input type=""text"" name=""objective" & i & """ size=""50"" onClick=""document.getElementById('obj" & b & "').style.display='inline';"" /><br />")
Response.Write("</span>")
Next

%>
</body>
</html>

I don't think you need to escape them all, just need to change the one round the onclick. 我认为您不必全部逃脱,只需更改onclick的一轮即可。 It expects a " but is getting a '. Replace you line of code with this and should have no problems: 它期望一个“,但得到一个'。用此替换您的代码行,应该没有问题:

Response.write(i & ") <input type='text' name='objective" & i & "' size='50' onClick=""document.getElementById('obj" & b & "').style.display='inline';"" /><br />")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM