Onclick Not Working?

Discussion in 'JavaScript' started by adamjblakey, Mar 21, 2008.

  1. #1
    Hi,

    Can someone help me with this:

    <input type="submit" name="Submit" value="Find" onclick="location.href="http://www.web.co.uk/" + document.getElementById("service").value + "/" + document.getElementById("location").value + "/";"/>
    Code (markup):
    It does not seem to work but cannot see what is wrong with it.

    Cheers,
    Adam
     
    adamjblakey, Mar 21, 2008 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There is syntax error there because the quotes are not properly enclosed/used.
    Try this:

    
    <input type="submit" name="Submit" value="Find" onclick="location.href='http://www.web.co.uk/' + document.getElementById('service').value + '/' + document.getElementById('location').value + '/';" />
    
    Code (markup):
     
    hogan_h, Mar 21, 2008 IP
  3. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You also might want to consider putting that code into the <form> tag (but use onsubmit instead of onclick), and follow it up with a return false; to make sure the form doesn't accidentally get posted.

    For example:

    
    <form onsubmit="location.href='http://www.web.co.uk/' + document.getElementById('service').value + '/' + document.getElementById('location').value + '/'; return false;">
    
    Code (markup):
     
    vpguy, Mar 21, 2008 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Thanks this works fine now,

    What i need to do, and i don't know if this is possible but i need when a selection is made i need that selection if contains spaces for the spaces to be removed and replaced with - also i need the address to be changed to all lowercase.

    Can this be done, if so how?
     
    adamjblakey, Mar 22, 2008 IP