HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 12th, 2005, 12:29 PM
bombulei bombulei is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 9 bombulei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 35 sec
Reputation Power: 0
Referencing html tag by its id or name?

is there anyway i can reference a tag by its name or id?
i'm trying to change an attribute such as style of regular table cell <td>. but i can not reach the cell by id or name.

i tried:

table_name.cell_name.style = ""
document.table_name.cell_name.style=""
and the same way with id but no success. could anyone help me.

Reply With Quote
  #2  
Old March 12th, 2005, 12:38 PM
EnenDaveyBoy's Avatar
EnenDaveyBoy EnenDaveyBoy is offline
Apprentice
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Sep 2003
Location: Manchester, England
Posts: 1,480 EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 1 m 29 sec
Reputation Power: 25
Send a message via ICQ to EnenDaveyBoy Send a message via AIM to EnenDaveyBoy Send a message via MSN to EnenDaveyBoy Send a message via Yahoo to EnenDaveyBoy
i take it your trying to use CSS then it would be something like

Code:

<html>
<head>
<style type="text/css">
<!--
.bgred {
	background-color: #FF0000;
}
-->
</style>
</head>

<body>
<table width="100%" border="1">
  <tr>
    <td class="bgred">data1</td>
    <td>data 2</td>
  </tr>
  <tr>
    <td>data 3</td>
    <td>data 4</td>
  </tr>
</table>


however if your trying to do this in asp.net then you may be better off trying the asp.net forum,

hope that help sorry fi it doesn't
__________________
Around a circle you can always draw a bigger circle.

EnenDaveyBoy

Reply With Quote
  #3  
Old March 12th, 2005, 12:41 PM
elijathegold's Avatar
elijathegold elijathegold is offline
Senior Fire Wizard
Click here for more information
 
Join Date: Feb 2005
Location: Ashford, Kent. England
Posts: 5,651 elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 2 Months 2 Weeks 2 Days 4 h 21 m 19 sec
Reputation Power: 301
Not really ASP but...

given
Code:
<td id="aCell">Blah</td>


you can use
Code:
document.getElementById("aCell").style.whatever


to access the style.

The whatever is the thing you want to change.

ie .width for width and so on

Elija

Reply With Quote
  #4  
Old March 12th, 2005, 01:03 PM
bombulei bombulei is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 9 bombulei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 35 sec
Reputation Power: 0
not java script but vb

this is java script to begin with. i need vb script.
and also this chunk of code is browser specific code. it doesn't work with all browser.

let me restate the question;

i am validating a asp form. and i have a asp function which is doing the validation. and my problem is when there is a problem with certain field, i want to change the text in front of that field, see my code:
<tr>
<td id="address">Address</td>
<td colspan="6"><input name="address1" id="address1" size="50"></td>
</tr>

i want change the color of label Address by referencing it with its id 'address'. but i am failing to reach this cell.

one more question how do u test if an asp page is loaded for the first time or if a submit button clicked?

thank you
Quote:
Originally Posted by elijathegold
Not really ASP but...

given
Code:
<td id="aCell">Blah</td>


you can use
Code:
document.getElementById("aCell").style.whatever


to access the style.

The whatever is the thing you want to change.

ie .width for width and so on

Elija

Reply With Quote
  #5  
Old March 12th, 2005, 01:20 PM
EnenDaveyBoy's Avatar
EnenDaveyBoy EnenDaveyBoy is offline
Apprentice
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Sep 2003
Location: Manchester, England
Posts: 1,480 EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 1 m 29 sec
Reputation Power: 25
Send a message via ICQ to EnenDaveyBoy Send a message via AIM to EnenDaveyBoy Send a message via MSN to EnenDaveyBoy Send a message via Yahoo to EnenDaveyBoy
try something like this

Code:

dim frm_email, email_color

frm_emial = request.form("emial")

if len(frm_email) > 0 then
emial_color = "#00ff00"
else 
email_color ="#0000ff"
end if



 <tr>
<td font="<%= email color%>>Address</td>
<td colspan="6"><input name="address1" id="address1" size="50"></td>
</tr>



this is very basic but should work

Hope that helps sorry if it doesn't

Reply With Quote
  #6  
Old March 12th, 2005, 01:24 PM
elijathegold's Avatar
elijathegold elijathegold is offline
Senior Fire Wizard
Click here for more information
 
Join Date: Feb 2005
Location: Ashford, Kent. England
Posts: 5,651 elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 2 Months 2 Weeks 2 Days 4 h 21 m 19 sec
Reputation Power: 301
Ah, I see...

Completely misunderstood.

Youre using server side validation and want to change the colour of the text when there is an error..

There is no way of using the DOM on the server (afaik) so you'll have to look at it slightly differently.

I don't know how your validation is working, so this may be unsuitable

Code:
     <tr>
         <td id="address"<% if address1NotValid then %> style="color:red;"<% end if %>>Address</td>
         <td colspan="6"><input name="address1" id="address1" size="50"></td>
               </tr>


where address1NotValid is the appropriate test for your script.

As I understood it document.getElementById("elementID").style.whatever is complient with standards. I am always prepared to be educated in this area tho

There are many ways you can test if a form has been submitted or not. The one that I use most often is simply to test a request.form("fieldInForm") and if the value exists, the form has been submitted.

In ASP.NET theres something called a postback, but I haven't really had the chance to play with .NET yet.

Hope this is more help

Elija

Reply With Quote
  #7  
Old March 12th, 2005, 01:45 PM
bombulei bombulei is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 9 bombulei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 35 sec
Reputation Power: 0
Elija,

can you explain that request.form("fieldInForm") little more detailed. i tried it but it never gets any value. maybe i'm using it wrong.
would very much appreciate if you could show me the other ways of testing the page is loaded 1st time or even testing if submit button was ever hit would do the trick too.

and the changing color of cell works. but again it is working every time the page is loaded. but i want it to work only when the submit button is hit but not b4.

thank you for your help

Quote:
Originally Posted by elijathegold
Ah, I see...

Completely misunderstood.

Youre using server side validation and want to change the colour of the text when there is an error..

There is no way of using the DOM on the server (afaik) so you'll have to look at it slightly differently.

I don't know how your validation is working, so this may be unsuitable

Code:
      <tr>
          <td id="address"<% if address1NotValid then %> style="color:red;"<% end if %>>Address</td>
          <td colspan="6"><input name="address1" id="address1" size="50"></td>
                </tr>


where address1NotValid is the appropriate test for your script.

As I understood it document.getElementById("elementID").style.whatever is complient with standards. I am always prepared to be educated in this area tho

There are many ways you can test if a form has been submitted or not. The one that I use most often is simply to test a request.form("fieldInForm") and if the value exists, the form has been submitted.

In ASP.NET theres something called a postback, but I haven't really had the chance to play with .NET yet.

Hope this is more help

Elija

Reply With Quote
  #8  
Old March 12th, 2005, 02:01 PM
EnenDaveyBoy's Avatar
EnenDaveyBoy EnenDaveyBoy is offline
Apprentice
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Sep 2003
Location: Manchester, England
Posts: 1,480 EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 1 m 29 sec
Reputation Power: 25
Send a message via ICQ to EnenDaveyBoy Send a message via AIM to EnenDaveyBoy Send a message via MSN to EnenDaveyBoy Send a message via Yahoo to EnenDaveyBoy
this line of code

<td id="address"<% if address1NotValid then %> style="color:red;"<% end if %>>Address</td>

should be

<td id="address" <% if address1NotValid then response.write("style='color:red;'") end if %>>Address</td>

request.form is used to get the information form a form element that has the method in the form as Post and request.querystring is used in the same way but when the form method is Get

here some more info

http://www.w3schools.com/asp/asp_inputforms.asp

hope that helps sorry if it doesn't

Last edited by EnenDaveyBoy : March 12th, 2005 at 02:05 PM.

Reply With Quote
  #9  
Old March 12th, 2005, 02:10 PM
elijathegold's Avatar
elijathegold elijathegold is offline
Senior Fire Wizard
Click here for more information
 
Join Date: Feb 2005
Location: Ashford, Kent. England
Posts: 5,651 elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 2 Months 2 Weeks 2 Days 4 h 21 m 19 sec
Reputation Power: 301
Certainly, this is a simple example to have a look at.

The key bits are that

1. Validation is in a function away from main program flow
2. A hidden field exists in the form.
3. This field is tested. If the value is empty, the form hasn't been submitted.

Save this code as demo.asp and try it.

Code:
   <%
   
     '  This is quick and dirty code - and probably not tested :)
   
     '  This is the function that validates a field.
     '  Passed in as a parm is the value of the field to test.
     '  It return true if valid or false if not
     function isFieldValid(fieldValue)
   
   	'  Start out optimistically
   	retVal = true
   
   	'  Simple validation - field must not be empty
   	if fieldValue = "" then retVal = false
   
   	'  Return the value to the caller
   	isFieldValid = retVal
   
     end function
   
     '  Get the fields from the form
     addressLine1 = request.form("addressLine1")
     isSubmitted = request.form("isSubmitted")
   
     '  If isSubmitted is empty, this is not a submit!
     '  Only validate if it is NOT Empty
     if isSubmitted <> "" then
   	isAddressLine1Valid = isFieldValid(addressLine1)
   	if not(isAddressLine1Valid) then
   	  className = "invalidFieldItem"
   	else
   	  className = ""
   	end if
     end if
   %>
   <html>
     <head>
   	<title>Test</title>
   	<style type="text/css">
   	  .invalidFieldItem { color: red; }
   	</style>
     </head>
     <body>
   	<form name="demoForm" id="demoForm action="demo.asp" method="post">
   	  <table>
   		<tr>
   		  <td class="<%=className%>">Address Line 1</td>
   		  <td>
 		 <input type="text" name="addressLine1" id="addressLine1" value="<%=addressLine1%>" />
 		 <!-- This next hidden control is what is tested to see if the form has been submitted -->
 		 <input type="hidden" name="isSubmitted" id="isSubmitted" value="1" />
   			<br />
   			<input type="submit" />
   		  </td>
   		</tr>
   	  </table>
   	</form>
     </body>
   </html>


Hope this helps and if you have any more questions, don't hesitate to ask.

Elija

Reply With Quote
  #10  
Old March 12th, 2005, 02:12 PM
elijathegold's Avatar
elijathegold elijathegold is offline
Senior Fire Wizard
Click here for more information
 
Join Date: Feb 2005
Location: Ashford, Kent. England
Posts: 5,651 elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1706335 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 2 Months 2 Weeks 2 Days 4 h 21 m 19 sec
Reputation Power: 301
Both those lines of code do the same thing... or at least they do if I haven't made a tipo

Elija

Quote:
Originally Posted by EnenDaveyBoy
this line of code

<td id="address"<% if address1NotValid then %> style="color:red;"<% end if %>>Address</td>

should be

<td id="address" <% if address1NotValid then response.write("style='color:red;'") end if %>>Address</td>

request.form is used to get the information form a form element that has the method in the form as Post and request.querystring is used in the same way but when the form method is Get

here some more info

http://www.w3schools.com/asp/asp_inputforms.asp

hope that helps sorry if it doesn't

Reply With Quote
  #11  
Old March 12th, 2005, 02:17 PM
EnenDaveyBoy's Avatar
EnenDaveyBoy EnenDaveyBoy is offline
Apprentice
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Sep 2003
Location: Manchester, England
Posts: 1,480 EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level)EnenDaveyBoy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 1 m 29 sec
Reputation Power: 25
Send a message via ICQ to EnenDaveyBoy Send a message via AIM to EnenDaveyBoy Send a message via MSN to EnenDaveyBoy Send a message via Yahoo to EnenDaveyBoy
lol ye i know the feeling lol

Reply With Quote
  #12  
Old March 12th, 2005, 02:55 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,628 Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)