当我选择贡献者时,我想更改上传文件名,它应该显示上传文件,如果选择编辑器,它应该显示上传文章。我写了代码,但是没有用。请帮助我。
这是选择按钮的源代码。您可以在图像中看到我的确切问题。
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">Register As<sup style="color:red">*</sup></label>
<div class="col-sm-7">
<label class="radio-inline">
<input type="radio" checked name="noaUserType" id="inlineRadio1" value="3"> Contributor
</label>
<label class="radio-inline">
<input type="radio" name="noaUserType" id="inlineRadio2" value="4"> Editor
</label>
</div>
</div>
<?php
if ($noaUserType == 3) {
$file = "Upload Article";
} else {
$file = "Upload File";
}
?>
<span id="noaSpanRegFileDivs">
<div id="noaDivRegFile_1" class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label"><?php echo $file; ?><sup style="color:red">*</sup></label>
<div class="col-sm-7 pos_r">
<input type="file" name="noaRegnFiles[]" class="form-control" id="noaRegnFile_0" style="height:auto;">
<div class="Addfile"><a href="Javascript:void(0);" id="noaBtnRegnFile_1" OnClick="noaRegnAddIFile(1);" class="btn btn-warning">Add File</a></div>
</div>
</div>
</span>
答案 0 :(得分:0)
您可以使用jQuery如下实现。
使用jQuery =>
$(function(){
$('input[type="radio"]').click(function(){
if ($(this).is(':checked'))
{
if( $(this).val()=='4' )
{
$("#uploadtext").text("Editor");
}
else
{
$("#uploadtext").text("File");
}
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">Register As<sup style="color:red">*</sup></label>
<div class="col-sm-7">
<label class="radio-inline">
<input type="radio" checked name="noaUserType" id="inlineRadio1" value="3"> Contributor
</label>
<label class="radio-inline">
<input type="radio" name="noaUserType" id="inlineRadio2" value="4"> Editor
</label>
</div>
</div>
<span id="noaSpanRegFileDivs">
<div id="noaDivRegFile_1" class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">Upload <span id="uploadtext">File</span><sup style="color:red">*</sup></label>
</div>
</span>