Jump to content


Photo

Java script Code Generator


  • This topic is locked This topic is locked
2 replies to this topic

#1 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 02 June 2003 - 09:28 AM

Hi this a Java script code generator . To use this paste the code in the HTML file for which u need a validation script. Put this script at the end of the page and browse the page in the browser. You will see the code shown in the HTML page. Copy the code and use it. :wink:

Hope this helps!!

<SCRIPT LANGUAGE=javascript>

<!--

document.write("function trim(strField)" + "<br>");

document.write("{" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;for(loop=0,space=0;strField.substr(loop,1)==" " &&loop < strField.length;loop++,space++);" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;strField=strField.substr(space,(strField.length-space));" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;for(loop=strField.length,space=0;strField.substr(loop-1,1)==" " && loop>0;loop--,space++);" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;strField=strField.substr(0,strField.length-space);" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;return strField;" + "<br>");

document.write("}" + "<br>");

document.write("function validateForm()" + "<br>");

document.write("{" + "<br>");

for(var i=0;i<document.forms[0].elements.length;i++)

{

	if(document.forms[0].elements[i].type=="text" |document.forms[0].elements[i].type=="textarea")

	{

  document.write("document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value=trim(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value);<br>");

	}

}

for(var i=0;i<document.forms[0].elements.length;i++)

{

	if(document.forms[0].elements[i].type=="select-one")

	{

  document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".selectedIndex==0)<br>");

  document.write("{<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert("Please select a value");<br>");  

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

  document.write("}<br>");

	}

	if(document.forms[0].elements[i].type=="text")

	{

  document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value=="")<br>");

  document.write("{<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert("Please enter a value");<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

  document.write("}<br>");

	}

	if(document.forms[0].elements[i].type=="password")

	{

  document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value=="")<br>");

  document.write("{<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert("Please enter a value");<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

  document.write("}<br>");

	}

	if(document.forms[0].elements[i].type=="checkbox")

	{

  document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".checked==false)<br>");

  document.write("{<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert("Please check a value");<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

  document.write("}<br>");

	}

	if(document.forms[0].elements[i].type=="radio")

	{

  document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".status==false)<br>");

  document.write("{<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert("Please check a value");<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

  document.write("}<br>");

	}

	if(document.forms[0].elements[i].type=="textarea")

	{

  document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value=="")<br>");

  document.write("{<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert("Please enter a value");<br>");  

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

  document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

  document.write("}<br>");

	}

}

document.write("return true;" + "<br>");

document.write("}" + "<br>");

//-->

</SCRIPT>

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#2 Dr Bloke

Dr Bloke
  • Members
  • Pip
  • Newbie
  • 1 posts
  • LocationLondon, England

Posted 18 February 2004 - 11:28 AM

The code has several unescaped quotes. I believe it should look like this:
<script LANGUAGE=javascript>

<!--

document.write("function trim(strField)" + "<br>");

document.write("{" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;for(loop=0,space=0;strField.substr(loop,1)==\" \" &&loop < strField.length;loop++,space++);" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;strField=strField.substr(space,(strField.length-space));" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;for(loop=strField.length,space=0;strField.substr(loop-1,1)==\" \" && loop>0;loop--,space++);" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;strField=strField.substr(0,strField.length-space);" + "<br>");

document.write("&nbsp;&nbsp;&nbsp;&nbsp;return strField;" + "<br>");

document.write("}" + "<br>");

document.write("function validateForm()" + "<br>");

document.write("{" + "<br>");

for(var i=0;i<document.forms[0].elements.length;i++)

{

if(document.forms[0].elements[i].type=="text" |document.forms[0].elements[i].type=="textarea")

{

 document.write("document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value=trim(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value);<br>");

}

}

for(var i=0;i<document.forms[0].elements.length;i++)

{

if(document.forms[0].elements[i].type=="select-one")

{

 document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".selectedIndex==0)<br>");

 document.write("{<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert(\"Please select a value\");<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

 document.write("}<br>");

}

if(document.forms[0].elements[i].type=="text")

{

 document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value==\"\")<br>");

 document.write("{<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert(\"Please enter a value\");<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

 document.write("}<br>");

}

if(document.forms[0].elements[i].type=="password")

{

 document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value==\"\")<br>");

 document.write("{<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert(\"Please enter a value\");<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

 document.write("}<br>");

}

if(document.forms[0].elements[i].type=="checkbox")

{

 document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".checked==false)<br>");

 document.write("{<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert(\"Please check a value\");<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

 document.write("}<br>");

}

if(document.forms[0].elements[i].type=="radio")

{

 document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".status==false)<br>");

 document.write("{<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert(\"Please check a value\");<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

 document.write("}<br>");

}

if(document.forms[0].elements[i].type=="textarea")

{

 document.write("if(document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".value==\"\")<br>");

 document.write("{<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;alert(\"Please enter a value\");<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;document."+document.forms[0].name+"."+document.forms[0].elements[i].name+".focus();<br>");

 document.write("&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>");

 document.write("}<br>");

}

}

document.write("return true;" + "<br>");

document.write("}" + "<br>");

//-->

</SCRIPT>

Dr Bloke

#3 PHP Monkeh

PHP Monkeh
  • Members
  • PipPipPip
  • Advanced Member
  • 409 posts
  • LocationUnited Kingdom

Posted 04 July 2004 - 09:17 PM

I pasted this code into a file and tried it out. What exactly is it supposed to do? All it does is echo the code you've told it to... don't see a point to the whole thing yet, anyone want to explain?
No monkey business
[br]Remember the manual PHP.net
Legacy Design




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users