Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Function with Form Input

Status
Not open for further replies.

CrimsonDiva

Programmer
Sep 22, 2000
30
0
0
US
Hello,

I'm trying to create a reusable Javascript function (used with ASP) that will take in a textarea and set a cook with the value of that textarea. my function works fine if i dont pass any parameters, but when i try to pass in the name of the form field, it doesn't work. I believe my problem has something to do with objects, but I can't seem to figure it out. Here's some of my code:

JAVASCRIPT
function OpenPreviewWindow(fld){
var theform = document.frmCreate;
var thefield = theform.fld; <== Not working
var now = new Date
strMessage = escape(document.frmRegister.signature.value);
document.cookie = &quot;Signature=&quot; + strMessage;
openWin('newwindow.asp')...
}

ASP
<FORM NAME=&quot;frmCreate&quot;...>
<A HREF=&quot;javascript: OpenPreviewWindow('openingblurb');&quot;>PreView Intro</A>
<TEXTAREA NAME=&quot;openingblurb&quot; ID=&quot;openingblurb&quot;...>

Please help!
Thanks,
Diva
 
oops. noticed a bug in my code print out. it should say this for the javascript:


JAVASCRIPT

function OpenPreviewWindow(fld){
var theform = document.frmCreate;
var thefield = theform.fld; <== Not working
var now = new Date
strMessage = escape(thefield.value);
document.cookie = &quot;Signature=&quot; + strMessage;
openWin('newwindow.asp')...
}

 
an example

<SCRIPT LANGUAGE=&quot;JScript&quot;>

function CheckNumber()
{
if (isNumeric(document.UserForm.AcctNo.value))
return true
else
{
alert(&quot;Please enter a valid account number.&quot;)
return false
}
}

//Function for determining if form value is a number.
//Note: The JScript isNaN method is a more elegant way to determine whether
//a value is not a number. However, some older browsers do not support this method.
function isNumeric(str)
{
for (var i=0; i < str.length; i++)
{
var ch = str.substring(i, i+1)
if( ch < &quot;0&quot; || ch>&quot;9&quot; || str.length == null)
{
return false
}
}
return true
}
</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top