www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Clicking <a> returns undefined.

  1. #1
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    84

    resolved [RESOLVED] Clicking <a> returns undefined.

    I have some js code where I would like to send the text of an <a> link to a textfield when clicked. Here is a live example: http://leke.dyndns.org/swe-ass2-autocomplete/
    I'm getting "undefined" though.

    Here are the important bits of my code...
    html:
    HTML Code:
    <input type="text" name="courseField" id="courseField" value="" style="width: 300px;" placeholder="Enter course name here" onKeyUp="showData(this.value)" />
    
    <div id="txtHint"></div>
    js:
    Code:
    function fillField(selected) {
    	document.getElementById("courseField").value=selected;
    }
    php (generated to js):
    PHP Code:
    echo '<a href="javascript:void(0)" onClick="fillField(this.value)">'.$line."</a><br />"
    Thanks

  2. #2
    Join Date
    Nov 2010
    Posts
    1,058
    a <a> tag doesn't have a value - try onClick="fillField(this.innerHTML)" for best cross-browser results

  3. #3
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    84
    Quote Originally Posted by xelawho View Post
    a <a> tag doesn't have a value - try onClick="fillField(this.innerHTML)" for best cross-browser results
    Thanks, that did the job

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles