I'm new on web designing and i have some problems while using JavaScript on HTML. You see i have this code:
<!DOCTYPE html>
<html>
<head>
<script src="Cod_JS.js"> </script>
<link href='Cod_Css.css' type=text/css rel=stylesheet>
</head>
<body>
<div>
<p id="un" class="uno">Esta es una prueba</p>
</div>
<br>
<form>
Color: <input type="text" name="color"> <br>
Fuente: <input type="text" name="fuente"><br>
<input type="submit" value="Enviar" onclick="funcion1(color,fuente)" >
</form>
</body>
</html>
And this is my JS code:
function funcion1(x,y)
{
var a=x.value;
var b=y.value;
if (a=="Rojo" && b=="Arial" )
{
var prueba=document.getElementById("un").className="dos";
}
else if (a=="Rojo" && b=="Calibri")
{
var prueba=document.getElementById("un").className="tres";
}
else if (a=="Verde" && b=="Arial")
{
var prueba=document.getElementById("un").className="cuatro";
}
else if (a=="Verde" && b=="Calibri")
{
var prueba=document.getElementById("un").className="cinco";
}
}
Basically what it does is i write on the input fields a color and a font and when i click submit JS will change the class of <p>
and then my CSS will recognize it and repaint it with the new color/font. However it does not change it for more than 1 sec. It blinks and goes back to normal. I know it's not the best method to do it but since my first time using JS i'm doing what i can haha.
Does anyone know why this is happening?
Thanks in advance!