Sorry if my question seems stupid as I am a total newbie.
I’m stuck with the following problem.
I need to add a fontawesome icon as the content of an input text according to a very simple condition defined by "if" as follows :
From the js file :
if (eval(form.current_weather.value)==1) { tag_box = HERE_I_need_to_place_a_fontawesome_icon1; }
else if (eval(form.current_weather.value)==2) { tag_box = HERE_I_need_to_place_a_fontawesome_icon2; }
else { tag_box1 = ""; }
From the html code :
Weather <select name="current_weather">
<option value="1">Rainy</option>
<option value="2">Cloudy</option>
<option value="3">Sunny</option>
</select>
I have the variable current_weather which is selected from a dropdown in html. Then, according to the entry selected from this dropdown, the variable tag_box will display a different fontawesome icon (#1 or #2) or no icon.
I really don’t know how to achieve this. I spent hours trying to understand javascript and testing with classes, remove.class etc but it is a total failure.
Could anyome help me with this, at least some advice. I would have preferred to use PHP but the get and post functions don’t return anything which is obvious actually.
Thanks in advance.
Regards.
3
Answers
please provide a screenshot or something so your problem is more understandable
Don’t worry, your question is not stupid at all, and it’s great that you’re trying to learn and solve a problem. To dynamically change the content of an input text based on the selected option in a dropdown and show FontAwesome icons accordingly, you can follow these steps using JavaScript:
<head>
section of your HTML file:This will load the FontAwesome library, which provides a wide range of icons.
<input>
element with the id "tag_box" where you want to display the FontAwesome icon:Now, when you select an option from the dropdown, the corresponding FontAwesome icon will be displayed in the input text box. If the selected option is not 1 or 2, the input box will be cleared.
Remember to adjust the icon classes in the JavaScript code to match the specific icons you want to use from FontAwesome. In this example, I used "fas fa-cloud-rain" for a rainy icon and "fas fa-cloud" for a cloudy icon. You can find more icons on the FontAwesome website and customize the icons as needed.
Same answer as @MH BIPUL but in Jquery,
You can download jquery from here (if you don’t have it aleady):
https://jquery.com/download/
in you .html file (just befor the tag closing):
This code can still be adjusted based on your senario.