473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Expected 'with' to have an indentation of 4 instead of 1.

14
hi guys.... i have this problem when i validate a form, any thoughts on this one?

Expand|Select|Wrap|Line Numbers
  1. function checkAddUserForm()
  2. {
  3.     with (window.document.frmAddUser) {
  4.         if (isEmpty(txtUserName, 'Enter user name')) {
  5.             return;
  6.         } else if (isEmpty(txtPassword, 'Enter password')) {
  7.             return;
  8.         } else {
  9.             submit();
  10.         }
  11.     }
  12. }
Jul 2 '07 #1
6 2336
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

What do you mean by 'indentation of 4 instead of 1'?

Do you get some sort of error?
Jul 2 '07 #2
rhx
14
Welcome to TSDN!

What do you mean by 'indentation of 4 instead of 1'?

Do you get some sort of error?
i tried checking the function with a js-verifier and got this error.. Problem at line 3 character 2: Expected 'with' to have an indentation of 4 instead of 1.

with (window.document.frmAddUser) {


while on firefox error console it says,

Error: window.document.frmAddUser has no properties


this is my form..
[HTML]<form action="processUser.php?action=add" method="post" enctype="multipart/form-data" name="frmAddUser" id="frmAddUser"">
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
<tr>
<td width="150" class="label">User Name</td>
<td class="content"> <input name="txtUserName" type="text" class="box" id="txtUserName" size="20" maxlength="20"></td>
</tr>
<tr>
<td width="150" class="label">Password</td>
<td class="content"> <input name="txtPassword" type="password" class="box" id="txtPassword" value="" size="20" maxlength="20"></td>
</tr>
</table>
<p align="center">
<input name="btnAddUser" type="button" id="btnAddUser" value="Add User" onClick="checkAddUserForm();" class="box">
&nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.location.href='index.php';" class="box">
</p>
</form>[/HTML]
Jul 2 '07 #3
acoder
16,027 Expert Mod 8TB
You should avoid using 'with' - see why.

In your case, here, you could just use document.getElementById to access the elements.
Jul 2 '07 #4
rhx
14
You should avoid using 'with' - see why.

In your case, here, you could just use document.getElementById to access the elements.
a lot of thanks acoder,

going back, i now have document.getElementById on my script, but it does not validates.

Expand|Select|Wrap|Line Numbers
  1. function checkAddUserForm() {
  2.     var txtUserName = document.getElementById('btnAddUser');
  3.     var txtPassword = document.getElementById('btnAddUser');
  4.  
  5.     if (txtUserName.value === "") {
  6.         return;
  7.     } else if (txtPassword.value === "") {
  8.         return;
  9.     } else {
  10.         submit();
  11.     }
  12. }
Jul 3 '07 #5
acoder
16,027 Expert Mod 8TB
On lines 2 and 3, the ids are incorrect. They should be 'txtUsername' and 'txtPassword'.

Instead of having a button calling this validation script, you could call the validate function onsubmit and have a submit button:
[HTML]<form name="..." id="..." action="..." onsubmit="return checkAddUserForm();">[/HTML] and [HTML]<input type="submit" value="Add User">[/HTML] In your validation function, you only need double equals when comparing. Also, return false instead of just 'return'-ing. One final thing: you don't need the submit method call, just return true instead.
Jul 3 '07 #6
rhx
14
On lines 2 and 3, the ids are incorrect. They should be 'txtUsername' and 'txtPassword'.

Instead of having a button calling this validation script, you could call the validate function onsubmit and have a submit button:
[HTML]<form name="..." id="..." action="..." onsubmit="return checkAddUserForm();">[/HTML] and [HTML]<input type="submit" value="Add User">[/HTML] In your validation function, you only need double equals when comparing. Also, return false instead of just 'return'-ing. One final thing: you don't need the submit method call, just return true instead.
thanks a lot acoder... i was able to fix some of the problems.
Jul 4 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Hilbert | last post by:
Hello, I'm using python to output RIB streams for Renderman. The RIB stream is a bunch of statements which describes a 3d image. The Rib standard allows for blocks which we usually indent for...
147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
8
by: valued customer | last post by:
Is there a way in python to indicate that you want your "base level of indentation" to be four spaces instead of zero? As far as I know now, the only way is by introducing some sort of language...
21
by: Asfand Yar Qazi | last post by:
Hi, After much use of tabs worth 8 spaces, and constantly having to format my C++ code in funny ways to keep all lines within an 80 character line length limit, I'm seriously thinking of...
10
by: Kelly | last post by:
EmployeeTable<Employee> employees;//where EmployeeTable is the array that stores the employees PositionIndex<EmployeeString>employee_nameIndex;//index for the array by last name and first name...
2
by: SJ | last post by:
I'm using codebehind to populate my datalist, but having a lot of trouble keeping the indentation of the datalist in place. This is what i'm doing right now : <asp:datalist id="LogList"...
13
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
11
by: ...:::JA:::... | last post by:
Hello, After my program read and translate this code: koristi os,sys; ispisi 'bok kaj ima'; into the: import os,sys;
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.