473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "<form><label for='user'>Or, find a dog by name:</label>\n
  3. <select name='findname' id='findname' class='selectOne'>\n
  4. <option value=''>Select name</option><option value=''>---------------</option>\n";
  5. sort($dogname);
  6. foreach ($dogname as $thisdog) {
  7.     echo "<option value='$thisdog'>$thisdog</option>\n";
  8. }
  9. echo "</select>\n";
  10. ?>
  11. <input type="button" value="Find" onClick='location.href=document.referrer+ "#" + dogname.value';/></form>
  12.  
The page as it currently stands can be seen at: http://www.greyhoundpets.com/Test2.php

Thanks for any help you can give.
Apr 20 '09 #1
6 2385
gits
5,390 Expert Mod 4TB
instaed of dogname.value just use:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('findname').value
kind regards
Apr 21 '09 #2
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!)
Apr 21 '09 #3
gits
5,390 Expert Mod 4TB
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
Apr 22 '09 #4
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.
Apr 22 '09 #5
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.
Apr 22 '09 #6
gits
5,390 Expert Mod 4TB
no problem ;) ... in case you would have any more questions just post back to the forum :)

kind regards
Apr 22 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Angelos | last post by:
Does anyone know if I can run a function when the link is click by writing something similar to that bellow ? <a href="" target="_blank" onClick="<? add_product_category(); ?>" >add...
2
by: orion30 | last post by:
Apparently, it's not possible to use the onClick event on a text, TR, TD elements using Firefox. I tried... Is-it true ? Is there an another solution ? Thank you
0
by: shen.chang.cs | last post by:
Hi, all, I use .Net V2.0 and WebControl TreeView. I want to have an OnClick() function to handle user click on certain end nodes but not on other nodes. Someone suggested to use a Java...
2
by: redpixel | last post by:
Hello everyone, I'm a fairly new to javascript and I need some help regarding element IDs. What I need is a simple javascript action that is attached to a checkbox that upon checking and...
9
by: monomaniac21 | last post by:
hi all i want to use hyperlinks to 'load' content by changing the display of div tags. the problem i have is that unless i specify a href the anchor does not change the mouse pointer on hover...
1
by: pankajit09 | last post by:
Please tell me the correct syntax of the below JS code --> newRow.onclick = clickedRowNo_new(newRowId,"configureIncidentDescription","true"); I am attaching a "onclick" event to a ROW of a...
4
by: since | last post by:
How do I in IE prevent the onclick action from being fired when I am done dragging? have tried "window.event.cancelBubble = true", for onmouseup , onmousedown, and onmousemove handlers. The onclick...
2
by: Jim Devenish | last post by:
I have set up shortcut menus on many form successfully. However, for the first time, I am trying to set one up on a subform. In the 'On Action:' when customising the menu item I have:...
0
by: Jim Devenish | last post by:
I have successfully added shortcut menus to Forms but I am now having difficulty when I attach a shortcut menu to a text control. I have a shortcut menu entitled 'CalendarEntries' with one command...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.