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

valdation-- arrays

Status
Not open for further replies.

kann

Programmer
Feb 16, 2000
25
0
0
US
Hai,<br>&nbsp;&nbsp;&nbsp;&nbsp;I am new to javascript.I would appreciate if some can help me.I have a field name &quot;vitemno&quot; which contains <br>22234a,23234b,8888u,999i8 <br>and one more text field &quot;invno&quot;.where the user will the invoiceno.<br><br>I Would like to know how to write javascript to check whether the invoiceno entered by the user matches the &quot;vitemno&quot;.if it matches i need throw error.<br><br><br>thanks<br><br>kann<br><br>
 
You can access the fields contents by using:<br>document.containingform.fieldname<font color=red>.value</font><br><br><A HREF="mailto:jared@aauser.com">jared@aauser.com</A>
 
I am unclear, but heres something:<br><br>if the first field (the one with four choices) is a &lt;select&gt;,<br><br>then you would need to do this to access the value of the selected item:<br><br>document.containingform.fieldname.options[document.containingform.selectedIndex].value<br><br>so, using this, and jaredn's line:<br>document.containingform.fieldname.value<br><br>we can write a script:<br><br>function check_if_bad(){<br>var select=document.containingform.select;<br>var otherField=document.containingform.fieldname;<br><br>if (select.options[select.selectedIndex].value==otherField.value){<br>alert('DO IT RIGHT!!!!');<br>return false} else {return true}<br><br>}<br><br>then insert this into the &lt;form&gt; tag:<br><br>onSubmit=&quot;return check_if_bad()&quot;<br><br>that way, if the two are equal, then the form won't submit, and an alert will fire.<br><br>but make sure to change the variables so that they refrence whats on the page.<br><br> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
hai,<br>&nbsp;&nbsp;&nbsp;&nbsp;Thanks for ur suggestion.I notice am making some silly mistake.<br><br>here is the script.<br><br>var val1 = window.document.forms[value1]<br><br>//LISTINVNO contains the list of values 0,1222,4343,9999<br>alert(val1.LISTINVNO.value); <br> var select1=val1.LISTINVNO.value;<br>//Order_Invno contains user input field to validate<br> var otherField=val1.Order_Invno;<br>&nbsp;&nbsp;&nbsp;if (select1.options[select1.selectedIndex].value==otherField.value){<br>&nbsp;&nbsp;alert('DO IT RIGHT!!!!');<br>&nbsp;&nbsp;//return false} else {return true}<br><br>}<br><br>Its shows error(option is null)<br><br><br>thanks<br><br>kann<br>
 
come on ! copy/past the CORRECT line !!<br>...<br>var select=document.containingform<font color=red>.select;</font><br>var otherField=document.containingform.fieldname;<br>...<br><br>and you wrote :<br>(i just replaced val1 by its value)<br>var select1=window.document.forms[value1]<br><font color=red>.LISTINVNO.value;</font><br>var otherField=val1.Order_Invno;<br>&nbsp;&nbsp;&nbsp;<br>see ? just kick the .value out<br><br>and READ THE DOC and a good idea would b to UNDERSAND WHAT YOU'RE DOING
 
&nbsp;&nbsp;jaredn,iza,the Eclipse.I really apprecaite ur help.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the Selectedindex is works fine for the &lt;select&gt;.but the LISTINVNO IS &quot;hidden&quot; field which contains <br>list of values(2223d,r333,444,4fr,rrf4).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;here i feel we should loop each value( i.e.&nbsp;&nbsp;LISTINVNO) with &quot;otherField.value&quot; to check the existence of the value.if exist throw the error.<br><br>here i Return the jscript.Unfornutaley the array.length shows 1.it should show the length of the array.<br><br>&nbsp;var val1 = window.document.forms[value1]<br> <br>myarray = new Array(val1.LISTINVNO.value);<br>alert(myarray);<br>alert(&quot; the length of array &quot; + myarray.length);<br><br>If(int i = 0&nbsp;&nbsp;; i &lt; myarray.length ; i++)<br>{<br>myarray<i>.value == otherfield.value;<br><br>alert(&quot; no duplicates value);<br><br>}<br><br><br>here is the problem i am facing here.<br><br>the LISTINVNO IS contain in<b>(1ff,1224fd,44d4,frff,rrgg)</b>;<br>if i create a&nbsp;&nbsp;the array its shows as single array.<br>is anyway we can make this as <b>(&quot;1ff&quot;,&quot;1224fd&quot;,&quot;44d4&quot;,&quot;frff&quot;,&quot;rrgg&quot;)</b> so that it will take as multiple array.<br><br>thanks<br><br>kann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top