Reply
value of <span> tag
Old 04-04-2008, 04:54 PM value of <span> tag
KkillgasmM's Avatar
Ultra Talker

Posts: 334
Name: El Phantasmo
Location: England, north west
Im trying to check / alter the value of a <span> tag, but with no luck. Here is the code Im using:

Code:
<p>
        <label for="userName" class="labelDef">Username <span class="highlight">*</span></label>
        <input type="text" name="userName" id="userName" />
        <span id="userNameValidate" class="highlight">invalid</span>
        <label>
        <input type="submit" name="button" id="button" value="Submit" onclick="validateUserName()" />
        </label>
      </p>
Code:
// JavaScript Document

function validateUserName()
    {
        var userName = document.form1.userName.value;
        var userNameValidate = document.form1.userNameValidate;
               
        alert(userNameValidate.value);
           
    }
But Firefox gives the error

Quote:
userNameValidate has no properties
Does anyone know what Im doing wrong??
__________________
http://www.inspindesign.co.uk
KkillgasmM is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-04-2008, 05:53 PM Re: value of <span> tag
Average Talker

Posts: 16
Name: andy
var userNameValidate = document.getElementById('userNameValidate').innerH TML
__________________
Web Design Bournemouth
womble is offline
Reply With Quote
View Public Profile
 
Old 04-04-2008, 06:46 PM Re: value of <span> tag
KkillgasmM's Avatar
Ultra Talker

Posts: 334
Name: El Phantasmo
Location: England, north west
Thanks but that doesnt seem to quite work. An alert box pops up but it just says 'undefined', rather than the text contained in the <span>

Do you know how I could do that?
__________________
http://www.inspindesign.co.uk
KkillgasmM is offline
Reply With Quote
View Public Profile
 
Old 04-04-2008, 06:49 PM Re: value of <span> tag
willcode4beer's Avatar
Webmaster Talker

Posts: 630
Name: Paul Davis
Location: San Francisco
Take a look at these:
getElementById()
http://developer.mozilla.org/en/docs...getElementById
the returned Element object:
http://developer.mozilla.org/en/docs/DOM:element
__________________
Paul Davis
willCode4Beer.com (coding for all the right reasons)
willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 04-05-2008, 05:01 AM Re: value of <span> tag
chrishirst's Avatar
Super Moderator

Posts: 11,866
Location: Blackpool. UK
Quote:
Originally Posted by KkillgasmM View Post
Thanks but that doesnt seem to quite work. An alert box pops up but it just says 'undefined', rather than the text contained in the <span>

Do you know how I could do that?
It should be innerHTML

(the forum adds random spaces to js code in posts. use the [code] delimiters to stop it happening)

eg:
Code:
var userNameValidate = document.getElementById('userNameValidate').innerHTML
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to value of <span> tag
 

Thread Tools

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

vB 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.13448 seconds with 13 queries