[英]onClick function to change html
I have a form which allows with some options to select a color and icon depending on the category that is being built, the issue I have found that it posts in everything I need but not what I am selecting, I have some hidden fields but it seems to just take the last one from the inputs instead of taking the vale from the one I select. 我有一个表格,其中允许您根据所构建的类别选择一些颜色和图标,我发现该问题将其发布在我需要的所有内容中,而不是我选择的内容,但我有一些隐藏的字段,但它似乎只是从输入中获取最后一个,而不是从我选择的中获取一个。
<!-- FORM TO DESIGN & CREATE A CATEGORY -->
<form action="actions/add_cat.php" method="post" id="rtf" name="">
<input type="text" name="cat_title" id="cat_title" required="required" placeholder="Category Title"/><br /><br />
<div class="catOptionsMenu">
<!-- COLOUR PICKER FOR CATEGORY HEADERS -->
<div class="redSelect" onclick="button_click('#d31b26');"><input type="hidden" name="cat_color" value="#f9c04c" ></div>
<div class="yellowSelect" onclick="button_click('#f9c04c');" ><input type="hidden" name="cat_color" value="#f9c04c" ></div>
<div class="blueSelect" onclick="button_click('#72bce9');"><input type="hidden" name="cat_color" value="#72bce9" ></div>
<div class="pinkSelect" onclick="button_click('#ec9292');"><input type="hidden" name="cat_color" value="#ec9292"></div>
<div class="greenSelect" onclick="button_click('#b7d04e');"><input type="hidden" name="cat_color" value="#b7d04e" ></div>
<div class="slateSelect" onclick="button_click('#637a91');"><input type="hidden" name="cat_color" value="#637a91" ></div>
<div class="purpleSelect" onclick="button_click('#AEA8D3');"><input type="hidden" name="cat_color" value="#AEA8D3" ></div>
<br><br>
<!-- ICON PICKER FOR CATEGORY HEADERS -->
<div class="iconSelect" onclick="button_click_icon1()">
<input type="hidden" name="cat_icon" value='<i class="fa fa-phone" style="font-size: 2em;"></i>' /><i class='fa fa-phone' style='font-size: 2em;'></i>
</div>
<div class="iconSelect" onclick="button_click_icon2()">
<input type="hidden" name="cat_icon" value='<i class="fa fa-graduation-cap" style="font-size: 2em;"></i>'><i class='fa fa-graduation-cap' style='font-size: 2em;'></i>
</div>
<div class="iconSelect" onclick="button_click_icon3()">
<input type="hidden" name="cat_icon" value='<i class="fa fa-users" style="font-size: 2em;"></i>'><i class='fa fa-users' style='font-size: 2em;'></i>
</div>
<div class="iconSelect" onclick="button_click_icon4()">
<input type="hidden" name="cat_icon" value='<i class="fa fa-question-circle" style="font-size: 2em;"></i>'><i class='fa fa-file-text' style='font-size: 2em;'></i>
</div>
<div class="iconSelect" onclick="button_click_icon5()">
<input type="hidden" name="cat_icon" value='<i class="fa fa-question-circle" style="font-size: 2em;"></i>'><i class='fa fa-question-circle' style='font-size: 2em;'></i>
</div>
</div>
<br><br>
<!-- CATEGORY HEADER DEMO BUILD VIEW -->
<div class="indexBox">
<div class="indexBoxHeader" id="box">
<siv id="icon"></div>
<div class="indexBoxFooter">
<div class='printchatbox' id='printchatbox'></div>
</div>
</div>
<br><br>
<input onclick="formsubmit()" type="submit" value="Create Category" name="submit"/>
Here are some inline functions to change the colors and icons to view what it looks like: 以下是一些内联函数,用于更改颜色和图标以查看其外观:
<!-- INLINE JS TO HANDLE THE CATEGORY BUILDER OPTIONS-->
<script type="text/javascript">
var inputBox = document.getElementById('cat_title');
inputBox.onkeyup = function(){
document.getElementById('printchatbox').innerHTML = inputBox.value;
}
function button_click(color){
document.getElementById("box").style.backgroundColor=color;
}
function button_click_icon1() {
document.getElementById("icon").innerHTML = "<i class='fa fa-phone' style='font-size: 2em;'</i>";
}
function button_click_icon2() {
document.getElementById("icon").innerHTML = "<i class='fa fa-graduation-cap' style='font-size: 2em;'</i>";
}
function button_click_icon3() {
document.getElementById("icon").innerHTML = "<i class='fa fa-users' style='font-size: 2em;'</i>";
}
function button_click_icon4() {
document.getElementById("icon").innerHTML = "<i class='fa fa-file-text' style='font-size: 2em;'</i>";
}
function button_click_icon5() {
document.getElementById("icon").innerHTML = "<i class='fa fa-question-circle' style='font-size: 2em;'</i>";
}
</script>
It isn't the nicest way to do it but my main worry is that of the posting and taking the last values and not the one I select? 这不是最好的方法,但是我主要担心的是发布和获取最后一个值,而不是我选择的那个?
So from the colour section, for example, you only need one of these: 因此,例如从颜色部分,您仅需要以下之一 :
<input type="hidden" name="cat_color" >
And modify your click function to update its value: 并修改您的click函数以更新其值:
function button_click(color){
document.getElementById("box").style.backgroundColor=color;
document.forms[0].cat_color.value = color;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.