3

I am trying to rewrite the W3C AJAX Livesearch script to echo a <button> instead of an <a>, which seems to be printing but the inline Javascript isn't responding to the AJAX script. Here is the PHP I've modified.

    $hint="<button='type' class='mybutton' name='users' value='" .
    $z->item(0)->childNodes->item(0)->nodeValue . "' onclick='showUser(this.value)'>" .
    $y->item(0)->childNodes->item(0)->nodeValue . "</button>";

I modified the the XML nodes to just contain a title and a value (1-n). The request seems to be working but it looks like the is not receiving a value. I have a feeling it is something to do with the way I've coded the PHP. Any thoughts? Thanks in advance!

EDIT: Problem answered, it was a simple syntax error in the markup. I took out my live example link, but refer to the W3C link if you are interested in learning the script. Good stuff!

13
  • Can you describe how it's not working? It looks fine to me; clicking the buttons loads the right details. Also, you should use CSS to change the button appearance. Don't use onmousedown, etc to change class names Commented Jan 7, 2014 at 23:55
  • @kingkero Looks like a typo. Doesn't look like that in OP's demo code Commented Jan 7, 2014 at 23:58
  • 2
    @Phil You do know it is about the dynamically loaded "button" - type in "Peter" in the input and you'll see ;) Commented Jan 8, 2014 at 0:01
  • 2
    Additionally I'd advise to stay off w3schools Commented Jan 8, 2014 at 0:10
  • 1
    I have always avoided W3C, but for once I was very please. They actually have some good AJAX stuff, so I've discovered. But yeah, not pleased with their JS and HTML5 articles. Commented Jan 8, 2014 at 0:43

1 Answer 1

3

The problem is the HTML you provide in the dynamically loaded content, which looks like this (from inspecting the given link):

<button='type' class="mybutton" name="users" value="1" 
    onclick="showUser(this.value)">Peter Griffin </button>

this.value returns undefined as you can see in this fiddle because this is no valid HTML syntax. You need to provide a proper button like the following:

<button class="mybutton" name="users" value="1"
    onclick="showUser(this.value)">Peter Griffin </button>
Sign up to request clarification or add additional context in comments.

2 Comments

FYI the AJAX response HTML doesn't actually have </button='type'>, that's just how your browser is interpreting it
Wow, I'm embarassed! Simple markup problem. I shouldn't have even posted this question, but it may be helpful for some. @Phil, please read the question again, I was having problems with Livesearch, not the buttons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.