Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by savgrec » Mon Nov 12, 2012 7:33 am
Hi,
Am trying to use this excerpt to change the contents with a pre-established set of text upon clicking those two textboxes with the same function, however it is not working as expected. I have used javascript instead of php as I couldn't make it up purely through php. I just can't figure out how to solve this little problem. Any help is highly appreciated. Thanks.
- Code: Select all
<html>
<head>
<title>Testing Assessment</title>
<script type="text/javascript">
function returnText(str)
{
switch (str) {
case "" : str="VG";
break;
case "VG" : str="G";
break;
case "G" : str="P";
break;
case "P" : str="N";
break;
case "N" : str="";
break;
default : str="";
break;
}
}
</script>
</head>
<body>
<form name=f1 action='' method=post>
Your Assessment 1: <input type=text name=t1 onclick='returnText(document.f1.t1.value)';><br>
Your Assessment 2: <input type=text name=t2 onclick='returnText(document.f1.t2.value)';><br>
</form>
</body>
</html>
-
savgrec
- New php-forum User

-
- Posts: 1
- Joined: Mon Nov 12, 2012 7:19 am
by MeroD » Mon Nov 12, 2012 10:46 pm
Have you tried:
document.getElementById("textboxelement").innerHTML = "Changed text!";
-
MeroD
- New php-forum User

-
- Posts: 53
- Joined: Wed Oct 10, 2012 12:14 am
by seandisanti » Tue Nov 13, 2012 9:28 am
1) you're not going to set a value without returning a value from the function
2) there are a lot of ways to do what you're trying, here's a jquery solution that works for me.
- Code: Select all
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("#t1").click(function(){
$("#t1").val(returnText$("#t2").val()));
});
$("#t2").click(function(){
$("#t2").val(returnText$("#t1").val()));
});
});
</script>
<script type="text/javascript">
function returnText(str)
{
switch (str) {
case "" : str="VG";
break;
case "VG" : str="G";
break;
case "G" : str="P";
break;
case "P" : str="N";
break;
case "N" : str="";
break;
default : str="";
break;
}
return str;
}
</script>
</head>
<body>
<form name=f1 action="#" method="post">
<input type="text" id="t1" />
<input type="text" id="t2" />
</form>
</body>
</html>
-
seandisanti
- php-forum Fan User

-
- Posts: 679
- Joined: Mon Oct 01, 2012 12:32 pm
Return to PHP coding => General
Who is online
Users browsing this forum: No registered users and 3 guests