Problem with onClick action syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TrevBriggs
    New Member
    • Apr 2009
    • 4

    Problem with onClick action syntax

    I have code that builds a page of dog information which includes a "name=" tag for each dog. The code also builds an array of dog names ($dogname).

    The following code is then supposed to create a simple form allowing the user to select a name from a list and click the "Find" button to go to the appropriate tag.
    Everything works as designed except the "find" function - I've spent many hours trying to get the syntax of this right without success. I've tried building the input button code both inside and outside the PHP. Here's the current version:

    Code:
    <?php
    echo "<form><label for='user'>Or, find a dog by name:</label>\n
    <select name='findname' id='findname' class='selectOne'>\n
    <option value=''>Select name</option><option value=''>---------------</option>\n";
    sort($dogname);
    foreach ($dogname as $thisdog) {
    	echo "<option value='$thisdog'>$thisdog</option>\n";
    }
    echo "</select>\n";
    ?>
    <input type="button" value="Find" onClick='location.href=document.referrer+ "#" + dogname.value';/></form>
    The page as it currently stands can be seen at: http://www.greyhoundpets.com/Test2.php

    Thanks for any help you can give.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    instaed of dogname.value just use:

    [CODE=javascript]document.getEle mentById('findn ame').value[/CODE]
    kind regards

    Comment

    • TrevBriggs
      New Member
      • Apr 2009
      • 4

      #3
      That worked! Excellent - you're a life-saver. Many thanks!

      (I don't know why I didn't notice that dogname.value was obviously wrong!)

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        glad to hear that ;) ... to get help for such simple problems you could use the firebug-extension for firefox ... which i always would recommend to use for webdevlopment tasks ... it would have shown here for example that dogname.value is undefined ...

        kind regards

        Comment

        • TrevBriggs
          New Member
          • Apr 2009
          • 4

          #5
          Thank you - I'll definitely look into firebug.

          I did make one change to the code. I found that the code worked as long as I went directly to my page by typing in the URL, but if I went to my home page first and then clicked the link to this page, when the "Find" button was pressed it took me back to the home page. I corrected this by changing "href=document. referrer" to "href=document. URL".

          Thanks again for taking the time to help with this.

          Comment

          • TrevBriggs
            New Member
            • Apr 2009
            • 4

            #6
            Wow - I've just looked at the firebug plug-in tool! What a fantastic resource - it will definitely save me a LOT of time. Thanks again for pointing it out to me.

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              no problem ;) ... in case you would have any more questions just post back to the forum :)

              kind regards

              Comment

              Working...