using onchange to insert text variable into url?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fishctr
    New Member
    • Feb 2008
    • 8

    using onchange to insert text variable into url?

    Hi there,
    I am trying to get a zip code lookup script to work. Basically, I want the user to input a zip code and the city and state are displayed without using a button to find it. I already have a zip code table in mysql. if i manually enter the ?zip= into the url, the city and state are displayed. my problem is getting the input into the url.


    any suggestions on where to look for solutions?
    here is my javascript function (which is probably where my problem is...i'm not well versed in js)
    Code:
    function checkZip() {
    var url = 'ContactEntryForm.php?zip=';
    var search = form.contactEntry.getElementById('zip').value;
    window.location.href='url+search';
    here is the code for the input
    Code:
    print "<tr><td>Zip</td><td><input type='text' name='mzip' id='zip' onchange='checkZip();' /></td>";
    Thanks!
  • fishctr
    New Member
    • Feb 2008
    • 8

    #2
    ok, i knew it would happen that I figure it out AFTER i post something. Anyway, if someone else has this problem, i found a solution here:


    I had to tweak it a bit (i erased the control.value+= control.value in the reallySetValue javascript function) because it was entering the input twice and therefore not searching the mysql database correctly.

    Comment

    • fishctr
      New Member
      • Feb 2008
      • 8

      #3


      sorry :( forgot to put in the url!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Was that the only problem?

        Surely, [code=javascript]window.location .href='url+sear ch';[/code] should be [code=javascript]window.location .href=url+searc h;[/code]?

        Comment

        Working...