|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
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:
|
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
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:
|
|
#8
|
||||
|
||||
|
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. |
|
#9
|
||||
|
||||
|
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 |
|
#10
|
||||
|
||||
|
Both those lines of code do the same thing... or at least they do if I haven't made a tipo
Elija Quote:
|
|
#11
|
||||
|
||||
|
lol ye i know the feeling lol
|
|
#12
|
||||
|