PDA

View Full Version : form problem



kimberlyhello
04-17-2007, 03:17 AM
Here is check.htm:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<form action="check.js" method="get" name="check">
<p>
<input name="keword" type="text" id="keword" size="30" maxlength="40">
<input type="submit" value="Check Username Availability">
</p>
</form>

</body>
</html>



The form action calls the check.js script. Here it is:

<SCRIPT language="JavaScript">
{

if(document.forms["check"].keyword.value.toLowerCase() == "kimberly"){
{document.write("<b>Taken</b>")}

if(document.forms["check"].keyword.value.toLowerCase() == "jennifer"){
{document.write("<b>Taken</b>")}

else {document.write("<b>Available</b>")}


}
</SCRIPT>

When I submit this form, the actual check.js page appears. Can someone tell me what is wrong.

thetestingsite
04-17-2007, 04:16 AM
You can't have a javascript as a form action. What you can do though is use the form "onSubmit" attribute to pass the information to another page (or accomplish your function).

So, your page would look like this:



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<SCRIPT language="JavaScript">
function check() {

if(document.forms["check"].keyword.value.toLowerCase() == "kimberly"){
{document.write("<b>Taken</b>")}

if(document.forms["check"].keyword.value.toLowerCase() == "jennifer"){
{document.write("<b>Taken</b>")}

else {document.write("<b>Available</b>")}

}

}
</SCRIPT>

<form action="" method="get" name="check" onsubmit="check(); return false;">
<p>
<input name="keword" type="text" id="keword" size="30" maxlength="40">
<input type="submit" value="Check Username Availability">
</p>
</form>

</body>
</html>


Hope this helps.

kimberlyhello
04-17-2007, 05:10 AM
it helps...

but it still doesn't work.

When I enter 'kimberly' or 'jennifer' into the text field...nothing happens when I press the button.

I want it to say "Taken"

Do you see any other problems with this script?

Thanks for your help.

codeexploiter
04-17-2007, 05:35 AM
Try the below mentioned code



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<SCRIPT language="JavaScript">
function checkFields()
{
var fieldValue = document.getElementById('keword').value;
fieldValue = fieldValue.toLowerCase();

if(fieldValue == "kimberly" || fieldValue == "jennifer")
{document.write("<b>Taken</b>");}
else
{document.write("<b>Available</b>");}
return false;
}
</SCRIPT>
<form action="" method="get" name="check" onsubmit="return checkFields();">
<p>
<input name="keword" type="text" id="keword" size="30" maxlength="40">
<input type="submit" value="Check Username Availability">
</p>
</form>

</body>
</html>

kimberlyhello
04-17-2007, 06:21 AM
Thank you both...it finally works!!!:D