Reputation: 39
I'm new to JavaScript and I want to make the textbox display a paragraph when i click the image based on what it displays on the dropbox but I've tried several methods and nothing works.
<script language="javascript" type="text/javascript">
function Select(){
var select = document.GetElementById("selection").value;
if(select == "mission")
{
document.getElementById("Par").value = "Johnny Bravo";
}
else{
document.getElementById("Par").value = "dadadadsa";
}
}
</script>
<body>
<p>Select any one:</p>
<form>
<select name = "dropdown" id="selection">1
<option value = "Mission" selected>Mission</option>
<option value = "Vision">Vision</option>
<option value = "Goal">Goal</option>
</select>
</form>
<img src="GC-CCS.jpg" alt="MissingImage" onclick="Select();"style="width:200px;height:200px;">
<input type="text" id="Par" size="50">
</body>
Upvotes: 1
Views: 32
Reputation: 68933
You have two issues in your code. Firstly, you have typo in GetElementById("selection")
(capital G
) and secondly, you have to lower case the value as "Mission" != "mission":
<script language="javascript" type="text/javascript">
function Select(){
var select = document.getElementById("selection").value.toLowerCase();
if(select == "mission"){
document.getElementById("Par").value = "Johnny Bravo";
}
else{
document.getElementById("Par").value = "dadadadsa";
}
}
</script>
<body>
<p>Select any one:</p>
<form>
<select name = "dropdown" id="selection">1
<option value = "Mission" selected>Mission</option>
<option value = "Vision">Vision</option>
<option value = "Goal">Goal</option>
</select>
</form>
<img src="GC-CCS.jpg" alt="MissingImage" onclick="Select();"style="width:200px;height:200px;">
<input type="text" id="Par" size="50">
</body>
Upvotes: 1