Listbox link keeps trying to open "null"

Discussion in 'HTML & Website Design' started by Captain_Ambiguous, May 26, 2011.

  1. #1
    <select OnChange="location.href=this.options[this.selectedIndex].value" multiple="multiple" name="People" style="height: 195px">
    <option value="listboxlink.html">Please select a link.
    <option value="@num" onclick="changeIt('image2');return false">Test 1
    <option value="http://www.tneoh.zoneit.com/cgi/upload">HTTP File Upload Demonstration.
    <option value="http://www.tneoh.zoneit.com">Simon's Website.
    </select>

    This is a listbox link script I'm tinkering with for my website. If you click on one of the "value = website" options then the specified page opens no problem but what I need from this is for the onclick event to trigger, you'll see an example in the second option value line.
    I've tried a couple of different configurations and what always happens (at best) is that the link tries to open the null value. If I use "#" then it reloads the page with "#" appended to the path name, if I use "#null" the same thing happens, same with "0" and if I don't put anything it just breaks. Oh and in no case does it execute the onclick :(
    Anyone with a greater understanding of script have an idea about this? Thanks
     
    Captain_Ambiguous, May 26, 2011 IP
  2. Captain_Ambiguous

    Captain_Ambiguous Active Member

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Okay I solved that problem by taking out the "onchange" option there but still the onclick isn't triggering when I select the test name. I really need to take a website design course one of these days :p Does anyone know what's missing?
     
    Captain_Ambiguous, May 26, 2011 IP
  3. Captain_Ambiguous

    Captain_Ambiguous Active Member

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Alright I've discovered that onclick isn't valid for the option tag, I'm surprised Sharepoint Designer didn't highlight that fact. So I'm researching and based on another post I found I changed my code to this:

    <select onchange="changeIt+escape(this.options[this.selectedIndex].text)" multiple="multiple" name="People" style="height: 195px">
    <option value="listboxlink.html">Please select a link.</option>
    <option value="('image2')">Test 1</option>
    <option value="http://www.tneoh.zoneit.com/cgi/upload">HTTP File Upload Demonstration.</option>
    <option value="http://www.tneoh.zoneit.com">Simon's Website.</option>
    </select>

    It still doesn't work but I know I'm close, can anyone point out the problem? The 2nd option line is the one I'm tinkering with, the changeIt function needs to be able to take the value of each line as its parameter. In a standard hyperlink it looks like this: onclick="changeIt('image2') and works.
     
    Captain_Ambiguous, May 26, 2011 IP
  4. Captain_Ambiguous

    Captain_Ambiguous Active Member

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    95
    #4
    :D Never mind I got it.

    <select onchange="changeIt(this.value) " multiple="multiple" name="People" style="height: 195px">
    <option value="listboxlink.html">Please select a link.</option>
    <option value="image2">Test 1</option>
    <option value="http://www.tneoh.zoneit.com/cgi/upload">HTTP File Upload Demonstration.</option>
    <option value="http://www.tneoh.zoneit.com">Simon's Website.</option>
    </select>
     
    Captain_Ambiguous, May 26, 2011 IP