<script type="text/javascript">
function changeValue(){
var option=document.getElementById('category').value;
if(option=="$category"){
document.getElementById('title').value="<php echo $category;?>";
}
else {
donothing
}
}
</script>
<select name="category" id="category" class="cat">
<option class="level-0" value="86" selected="selected">Op1</option>
<option class="level-0" value="93"> Op 2</option>
<option class="level-0" value="125"> Op 3</option>
</select>
<label for="title"><?php _e('Title', 'variable'); ?> <span title="required">* </span></label> <input type="text" class="text" name="title" id="title" value="//Here is the thing I do not know what to put here”?>" />
大家好:
我阅读了另一篇文章并提出了一种方法,一旦该人从其中一个选项中进行选择,该选项的名称将自动填充标题输入字段的值。我怎样才能做到这一点?我尝试了很多次,回声只是没有这样做。请帮忙!
谢谢你
已清除,但下面有更多更新问题---------------------------------------------------- 我似乎看不到得到了我的表单的脚本工作。我尝试通过写入插入脚本:
<?php
//( I put the function script into a separated .js file, only function itself is included in the .js file)
echo '<script type="text/javascript" src="autocat.js">';
echo '</script>';
?>
将上面的代码放入生成表单的我的 php 文件中。
我尝试在表单标签开始之前插入它,但似乎根本不起作用......你知道可能是什么错误吗?Chrome表示脚本状态已取消。
为了清楚起见,下面的代码在 autocat.js 中:
function changeValue(val){
document.getElementById('title').value= obj[obj.selectedIndex].innerHTML;
}
Chrome 还报道了:
加载资源失败:服务器响应我的 autocat.js 文件的状态为 404(未找到)
更新
我清除了上面的错误,但是现在代码还可以,但是当我触发表单时,似乎 onChange 没有运行...可能是因为表单在 PHP 生成表单之前解析了 javaScript 吗?
谢谢你