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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript in cfform 1

Status
Not open for further replies.

olmos

Technical User
Oct 25, 2000
135
US
I used a javascript which uses regular expressions to check input for an ip address, a pop box alerts you if you have not entered the IP address format correctly . It works fine with a regular html form but does not work in my cold fusion form. I placed it between the Head tags I also have other cold fusion processing stuff in the same page and have required fields in my form for example: <INPUT TYPE=&quot;hidden&quot; NAME=&quot;SYSTEM_LOCATION_required&quot; VALUE=&quot;Missing System Location&quot;>. Is it because I am also using the required fields on the same page or other processing?

Thanks in advance ,
olmos




 
Hey Olmos,

Adding the CF validation fields shouldn't affect the JS validation for the other field(s) unless you have it set to check all inputs. If you can post the JS along with everything between your form tags, I or someone else in the forums should be able to help.

GJ
 
Here's the code below and I do have it set to check all inputs since the fields are all required. This may be the problem. I would really appreciate if someone can check it and let me know what's wrong. By the way, thanks GunJack for your help with my previous post on formatting an IP . I decided to change the datatype to CHAR makes it easier to retrieve and am using this javascript to check for formatting the IP.

thanks,
Olmos

<CFPARAM NAME=&quot;action&quot; DEFAULT=&quot; &quot;>

<CFQUERY NAME=&quot;qry_fn_id&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>

SELECT max(FN_ID) AS maxFN_ID
FROM scott.f_natl

</CFQUERY>

<CFSET l_fn_id = qry_fn_id.maxFN_ID>

<CFIF action EQ &quot;insert&quot;>

<CFTRANSACTION>

<CFQUERY NAME=&quot;qry_fn_id&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>

SELECT max(FN_ID) AS maxFN_ID
FROM scott.f_natl

</CFQUERY>

<CFSET l_fn_id = qry_fn_id.maxFN_ID>

<CFQUERY NAME=&quot;ADDCOMPUTER&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>


INSERT INTO scott.fn_computer

( FN_ID, COMPUTER_NO, SYSTEM_NAME, SYSTEM_IP )

VALUES
( #l_fn_id#, '#Form.COMPUTER_NO#', '#Form.SYSTEM_NAME#', '#Form.SYSTEM_IP#')

</CFQUERY>
</CFTRANSACTION>

</CFIF>


<CFIF #ParameterExists(EditComputer)# IS &quot;Yes&quot;>

<CFQUERY NAME=&quot;UpdateComputer&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>


UPDATE scott.fn_computer

SET FN_ID=#l_fn_id#, COMPUTER_NO = '#form.COMPUTER_NO#', SYSTEM_NAME = '#form.SYSTEM_NAME#', SYSTEM_IP= #form.SYSTEM_IP#

WHERE fn_computer.FN_COMPUTER_ID = #form.FN_COMPUTER_ID#

</CFQUERY>

</CFIF>


<CFIF #ParameterExists(DeleteComputer)# IS &quot;Yes&quot;>

<CFQUERY NAME=&quot;DeleteComputer&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>


DELETE FROM scott.fn_computer

WHERE fn_computer.FN_COMPUTER_ID = #form.FN_COMPUTER_ID#


</CFQUERY>

</CFIF>

<CFTRANSACTION>

<CFQUERY NAME=&quot;qry_fn_id&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>

SELECT max(FN_ID) AS maxFN_ID
FROM scott.f_natl
</CFQUERY>

<CFSET l_fn_id = qry_fn_id.maxFN_ID>


<CFQUERY NAME=&quot;SHOWRECORDS&quot; DATASOURCE=&quot;IT&quot; dbtype=&quot;Oracle80&quot;>


SELECT f_natl.sponsor_name, f_natl.visitor_name, fn_computer.FN_COMPUTER_ID, fn_computer.FN_ID, fn_computer.COMPUTER_NO , fn_computer.SYSTEM_NAME, fn_computer.SYSTEM_IP

FROM scott.f_natl , scott.fn_computer

WHERE f_natl.FN_ID = fn_computer.FN_ID

AND fn_computer.FN_ID = #l_fn_id#

</CFQUERY>

</CFTRANSACTION>

<HTML>
<HEAD>
<TITLE>
</TITLE>

<script language=&quot;JavaScript1.2&quot;><!--

function validate(form) {

var str = form.system_ip.value;

var re = /^[1-9]{3}\.[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}/;

if (form.system_ip.value == &quot;&quot;) {
alert(&quot;Please enter your System IP address.&quot;);
form.system_ip.focus();
return false;
}
if (re.test(str)) {
return true;
}
alert(&quot;&quot; + str + &quot; is an invalid IP Address!&quot;);
form.system_ip.select();
form.system_ip.focus();
return false;
}

// --></script>


</HEAD>

<BODY>

<form ACTION=&quot;formgrid.cfm&quot; method=&quot;post&quot; onSubmit=&quot;return validate(this)&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;action&quot; VALUE=&quot;edit&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;action&quot; VALUE=&quot;#qry_fn_id.l_fn_id#&quot;>
<CENTER>
<H1>Computer Access</H1>
</CENTER>
<P>
<CFOUTPUT QUERY=&quot;SHOWRECORDS&quot;>

<H2>Computer List: </h2>
<INPUT TYPE= &quot;hidden&quot; NAME=&quot;fn_computer_id&quot; VALUE= &quot;#fn_computer_id#&quot;>
<TABLE border=&quot;1&quot;>
<TR>
<TH></TH>
<TH></TH>
<TH>FN_ID</TH>
<TH>COMP. NUMBER</TH>
<TH>SYSTEM NAME</TH>
<TH>SYSTEM IP</TH>
</TR>

<TR>
<TD><A HREF=&quot;editformgrid2.cfm?fn_computer_id=#fn_computer_id#&quot;><FONT SIZE=-1>[EDIT]</FONT></A></TD>

<TD><A HREF=&quot;deleteformgrid2.cfm?fn_computer_id=#fn_computer_id#&quot;><FONT SIZE=-1>[DELETE]</FONT></A></TD>

<TD>#FN_ID#</TD>
<TD>#COMPUTER_NO#</TD>
<TD>#SYSTEM_NAME#</TD>
<TD>#SYSTEM_IP#</TD>
</TR>
</form>

<FORM ACTION=&quot;submitcomplete2.cfm&quot; method=&quot;post&quot; >

Click done when computer list is complete <INPUT TYPE=&quot;submit&quot; VALUE=&quot;Done&quot;>

</form>
</CFOUTPUT>
</TABLE>
</form>

<HR>

<H2>Enter New Computer Information:</H2>

<p>
<FORM NAME = &quot;computerinfo&quot; ACTION=&quot;formgrid2.cfm&quot; method=&quot;post&quot; onSubmit=&quot;return validate(this)&quot;>

<INPUT TYPE=&quot;hidden&quot; NAME=&quot;action&quot; VALUE=&quot;insert&quot;>
<INPUT TYPE= &quot;hidden&quot; NAME=&quot;fn_id&quot; VALUE= &quot;#fn_id#&quot;>
<INPUT TYPE= &quot;hidden&quot; NAME=&quot;fn_computer_id&quot; VALUE= &quot;#fn_computer_id#&quot;>

<INPUT TYPE=&quot;hidden&quot; NAME=&quot;COMPUTER_NO_required&quot; VALUE=&quot;Missing Computer Number&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;SYSTEM_NAME_required&quot; VALUE=&quot;Missing System Name&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;SYSTEM_IP_required&quot; VALUE=&quot;Missing System IP&quot;>

<table width=&quot;100%&quot; align = &quot;center&quot; border = &quot;1&quot; cellpadding=2 cellspacing=2 bgcolor=#ffffcc>

<INPUT TYPE= &quot;hidden&quot; NAME=&quot;fn_id&quot; VALUE= &quot;#fn_id#&quot;>
<INPUT TYPE= &quot;hidden&quot; NAME=&quot;fn_computer_id&quot; VALUE= &quot;#fn_computer_id#&quot;>

<tr>
<td>
<font size=-1><a href=&quot;computer_no.html&quot; target=&quot;_blank&quot;>* COMPUTER_</a></font><br>
<input type=text size=15 maxlength=9 name=&quot;COMPUTER_NO&quot; >
</td>
<td><font size=-1><a href=&quot;system_ip.html&quot; target=&quot;_blank&quot;>* IP ADDRESS OF SYSTEMS</a></font><br>
<input type=text size=15 maxlength=15 name=&quot;SYSTEM_IP&quot; >
</td>
<td><font size=-1><a href=&quot;name_of_systems.html&quot; target=&quot;_blank&quot;>* NAME OF SYSTEM</a></font><br>
<input type=text size=30 maxlength=30 name=&quot;SYSTEM_NAME&quot; >
</td>
</tr>

</table>

<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Add Computer to list&quot; >

</FORM>

<FORM ACTION=&quot;submitcomplete2.cfm&quot; method=&quot;post&quot;>

Click done when computer list is complete

<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Done&quot;>

</form>

</BODY>
</HTML>



 
what is not working ? which browser do you use ? and you didn't need to post ALL the code for the page (for instance cfquery's are irrelevant !) - javascript and form parts would have been enough !
 
Hey Olmos,

The only problem I see is that the first form to use your validation

<form ACTION=&quot;formgrid.cfm&quot; method=&quot;post&quot; onSubmit=&quot;return
validate(this)&quot;>

doesn't have an input &quot;system_ip&quot;. This would cause the validation to fail for this form. The second form that uses the validation does have an input and I don't see any reason why it wouldn't work. Can you tell me what happens when you submit the form? Iow, does it not submit because the validation fails, does it always submit even with invalid IPs, etc... I need to know what you're seeing a problem with so I know where to look.

GJ
 
I am using netscape 4.7 and this will be the browser that the users will be using.
It submits to the action page even with invalid IP's. I never see the alert box. I took off the ...onSubmit=&quot;return validate(this)&quot;> for the first form. It still isn't working.

thanks,
olmos
 
Hey Olmos,

I didn't spot it at first and had to re-create your script to see what was happening. Since JS is case sensitive, you need to make sure your input variable name is the same as what you're referencing in your validation function. In validate(), you reference the field as &quot;form.system_ip&quot; but you define it as &quot;SYSTEM_IP&quot;. If you change the input box to this,

<input type=text size=15 maxlength=15 name=&quot;system_ip&quot; >

I think it will work for you as it did with my browser.

Let me know if you still have problems,
GJ
 
Thanks alot for your help . It worked!!

olmos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top