Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Validation and distinguishing between remote and local images
Old 06-26-2007, 06:57 PM Validation and distinguishing between remote and local images
Average Talker

Posts: 23
Trades: 0
Okay, I have two issues that are kind of one in the same.

First off, I am trying to validate some forms I have. The form of validation I am using is from this link:
http://www.javascript-coder.com/html...lidation.phtml

In my form, I have a few fields which are not required, but if a certain field has a value then another field would be required. For example, if the user input a number for 'mileage' then they should also be required to provide 'mileage_units'. I tried several techniques to get this to work, but none of them work. 'undefined' was my last attempt. I have tried != '' as well, but that also did not work.

Secondly, I allow users to provide an image with this form. They can choose to upload an image from their local machine, or they can provide a remote URL of an image. What I want to do is integrate my validation to ensure they are not providing both of the image types. I tried to do some of the custom validation the script uses, but to no avail. I am pretty new to js although I do kind of understand it, just new to the object oriented aspect. Along with this, I am unsure of how to code the checks to see which image was provided. Any PHP suggestions for that would also be warranted.

Below is my generated source of the form as well as the js validation following....any help would be greatly appreciated!

Code:
<form id="add_vehicle" enctype="multipart/form-data" method="post" name="add_vehicle" action="index.php?action=garage;sa=insert_vehicle">
    <table border="0" cellpadding="3" cellspacing="1" width="100%" class="bordercolor">
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Year</b>&nbsp;<style="color:#FF0000">[Required]</td>
        <td class="windowbg"><select id="made_year" name="made_year">
        <option value="" selected="selected">Select Year</option>         <option value="1980">1980</option>
        <option value="1981">1981</option>
        <option value="1982">1982</option>
        <option value="1983">1983</option>
        <option value="1984">1984</option>
        <option value="1985">1985</option>         <option value="1986">1986</option>
        <option value="1987">1987</option>
        <option value="1988">1988</option>
        <option value="1989">1989</option>
        <option value="1990">1990</option>
        <option value="1991">1991</option>         <option value="1992">1992</option>
        <option value="1993">1993</option>
        <option value="1994">1994</option>
        <option value="1995">1995</option>
        <option value="1996">1996</option>
        <option value="1997">1997</option>         <option value="1998">1998</option>
        <option value="1999">1999</option>
        <option value="2000">2000</option>
        <option value="2001">2001</option>
        <option value="2002">2002</option>
        <option value="2003">2003</option>         <option value="2004">2004</option>
        <option value="2005">2005</option>
        <option value="2006">2006</option>
        <option value="2007">2007</option>
        <option value="2008">2008</option>
        </select>         </td>
    </tr>
    
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Make</b>&nbsp;<style="color:#FF0000">[Required]</td>
        <td class="windowbg"><select id="make_id" name="make_id">
                             <option value="">Select Make</option>
                             <option value="">------</option><option value="1">AC</option><option value="2">Acura</option><option value="3">Aixam</option><option value="4">Alfa-Romeo</option><option value="5">Asia</option><option value="6">Aston-Martin</option><option value="7">Audi</option><option value="8">Austin</option><option value="9">Bentley</option><option value="10">BMW</option><option value="11">Bristol</option><option value="12">Cadillac</option><option value="13">Caterham</option><option value="14">Chevrolet</option><option value="15">Chrysler</option><option value="16">Citroen</option><option value="17">Daewoo</option><option value="18">Daihatsu</option><option value="19">Daimler</option><option value="20">Datsun</option><option value="21">Delorian</option><option value="22">Dodge</option><option value="23">Ferrari</option><option value="24">Fiat</option><option value="25">Ford</option><option value="26">FSO</option><option value="27">Ginetta</option><option value="28">Griffon</option><option value="29">Hillman</option><option value="30">HMC</option><option value="31">Honda</option><option value="32">Hummer</option><option value="33">Hyundai</option><option value="34">ISO</option><option value="35">Isuzu</option><option value="36">Jaguar</option><option value="37">Jeep</option><option value="38">Jensen</option><option value="39">Kia</option><option value="40">Lada</option><option value="41">Lamborghini</option><option value="42">Lancia</option><option value="43">Land Rover</option><option value="44">Lexus</option><option value="45">Ligier</option><option value="46">Lincoln</option><option value="47">Lotus</option><option value="48">Marcos</option><option value="49">Maserati</option><option value="50">Maybach</option><option value="51">Mazda</option><option value="52">McLaren</option><option value="53">Mercedes-Benz</option><option value="54">MG</option><option value="55">Microcar</option><option value="56">Mini</option><option value="57">Mitsubishi</option><option value="58">Morgan</option><option value="59">Morris</option><option value="95">Nissan</option><option value="60">Noble</option><option value="61">Opel</option><option value="62">Pagani</option><option value="63">Panther</option><option value="64">Perodua</option><option value="65">Peugeot</option><option value="66">Pontiac</option><option value="67">Porsche</option><option value="68">Proton</option><option value="69">Reliant</option><option value="70">Renault</option><option value="71">Riley</option><option value="72">Rolls Royce</option><option value="73">Rover</option><option value="74">Saab</option><option value="75">Sao</option><option value="76">Seat</option><option value="77">Singer</option><option value="78">Skoda</option><option value="79">Smart</option><option value="80">SsangYong</option><option value="81">Subaru</option><option value="82">Sunbeam</option><option value="83">Suzuki</option><option value="84">Talbot</option><option value="85">Tata</option><option value="86">Toyota</option><option value="87">Triumph</option><option value="88">TVR</option><option value="89">Ultima</option><option value="90">Vauxhall</option><option value="91">Volkswagen</option><option value="92">Volvo</option><option value="93">Westfield</option><option value="94">Yugo</option></select>                              &nbsp;Not Listed? Click <a href="javascript:add_make()">Here</a>
        </td>
    </tr>
    
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Model</b>&nbsp;<style="color:#FF0000">[Required]</td>
        <td class="windowbg"><select id="model_id" name="model_id">
                             <script type="text/javascript">dol.printOptions("model_id")</script>                              </select>
                             &nbsp;Not Listed? Click <a href="javascript:add_model()">Here</a>
        </td>
    </tr>
    
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Engine Type</b></td>
        <td class="windowbg"><select id="engine_type" name="engine_type">
                             <option value="">Select Engine Type</option>
                             <option value="">------</option><option value="1">8 Cylinder Naturally</option><option value="2">8 Cylinder Forced Induction</option><option value="3">6 Cylinder Naturally</option><option value="4">6 Cylinder Forced Induction</option><option value="5">4 Cylinder Naturally</option><option value="6">4 Cylinder Forced Induction</option>
                             </select>
        </td>
    </tr>     
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Color</b></td>
        <td class="windowbg"><input name="color" type="text" size="20" value="" /></td>
    </tr>
    
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Mileage</b></td>
        <td class="windowbg"><input name="mileage" type="text" size="15" value="" />&nbsp;
                             <select id="mileage_units" name="mileage_units">
                             <option value="">Select Mileage Type</option>
                             <option value="">------</option>
                             <option value="Miles" >Miles</option>
                             <option value="Kilometers" >Kilometers</option>
                             </select>
        </td>
    </tr>     
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Purchased Price</b></td>
        <td class="windowbg"><input name="price" type="text" size="10" value="" />&nbsp;Currency:&nbsp;
                             <select id="currency" name="currency">
                             <option value="">Select Currency</option>
                             <option value="">------</option><option value="1">GBP</option><option value="2">USD</option><option value="3">EUR</option><option value="4">CAD</option><option value="5">YEN</option>                              </select>
        </td>
    </tr>
    
    <tr>
        <td class="windowbg2" width="20%" align="right"><b>Description</b></td>
        <td class="windowbg"><textarea name="comments" cols="60" rows="5" wrap="soft" value=""></textarea></td>
    </tr>
    <tr>
        <td class="titlebg" align="center" height="28" colspan="3">Image Attachments</td>
    </tr>
    
    <tr>
        <td class="windowbg2" width="32%" align="right" nowrap="nowrap"><b>You may attach an image.<br />Maximum file size : 1024 kbytes<br />Maximum resolution : 1024</b></td>
        <td class="windowbg" colspan="3"><input size="30" type="file" size="30" name="FILE_UPLOAD"/></td>
    </tr>    
    <tr>
        <td class="windowbg2" width="32%" align="right"><b>Enter a URL to an online image</b></td>
        <td class="windowbg" colspan="3"><input name="url_image" type="text" size="40" maxlength="255" value="http://" /></td>
    </tr>    
    <tr>
        <td class="windowbg2" width="32%" align="right"><b>Description</b></td>
        <td class="windowbg"><textarea name="attach_desc" cols="60" rows="3" wrap="soft" value=""></textarea></td>
    </tr>    
    <tr>
        <td colspan="2" class="titlebg" align="center" height="28"><input type="hidden" value="" name="VID" /><input type="hidden" name="sc" value="816f46b1ee0d9d288aef8583f5de2cc5" /><input name="Create New Vehicle" type="submit" value="Create New Vehicle" /></td>
    </tr>
    </table>
</td>
</tr>
    <tr>
        <td class="titlebg" align="center" height="28">&nbsp;</td>
    </tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
 var frmvalidator = new Validator("add_vehicle");
 var frm = document.forms["add_vehicle"];
 
 frmvalidator.addValidation("made_year","req","Please select a year.");
 frmvalidator.addValidation("made_year","dontselect=0","Please select a year.");
 
 frmvalidator.addValidation("make_id","req","Please select a make.");
 frmvalidator.addValidation("make_id","dontselect=0","Please select a make.");
 frmvalidator.addValidation("make_id","dontselect=1","Please select a make.");
 
 frmvalidator.addValidation("model_id","req","Please select a model.");
 
 frmvalidator.addValidation("color","regexp=^[A-Za-z]{1,20}$","Color must consist of letters only and have a maximum of 20 characters.");
 
 frmvalidator.addValidation("mileage","numeric","Mileage must be a numeric value.");
 if(frm.mileage.value != undefined)
  { 
    frmvalidator.addValidation("mileage_units","req","Please select a mileage unit.");
    frmvalidator.addValidation("mileage_units","dontselect=0","Please select a mileage unit.");    
  }
  
 frmvalidator.addValidation("price","numeric","Price must be a numeric value.");
 if(frm.price.value != undefined)
  { 
    frmvalidator.addValidation("currency","req","Please select a currency.");
    frmvalidator.addValidation("currency","dontselect=0","Please select a currency."); 
  }
  
  frmvalidator.addValidation("comments","maxlen=500","Description must be less than 500 characters.");
  
</script>
RRasco is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Validation and distinguishing between remote and local images
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15277 seconds with 12 queries