Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    function converturl() help or suggestions

    I'm hoping someone can help. I'm very new to javascipt and am attempting to create a form that has hidden values to pass to Bing Search. I'm also trying to add a drop down menu that causes the value from the option the user changes to be passed along in the same url.

    In short, if the user adds "java" in the text box and chooses "dallas" from the drop down menu it will incorporate these variables into the url along with the hidden words that are static, being "resume NOT jobs NOT apply". The url would end up looking something like: http://www.bing.com/search?&q=Resume+-jobs+-apply+java+"Dallas"

    This is the code I have currently, that just fails
    <code>
    <script>
    function converturl() {
    document.go.url.value = document.go.url.value.replace(/\s/g, "");
    var url = document.getElementsByName("url")[0];
    var city = document.getElementsByName("city")[0];
    var fullurl = document.getElementsByName("fullurl")[0];
    fullurl.value = "http://www.bing.com/search?&q=Resume+-jobs+-apply+-submit+-required+-wanted+-template+-wizard+-free+-write+-sample+" + url.value.city

    }

    </script>


    <form name= "go" onsubmit='converturl();location.href=fullurl.value.city;return false'>
    <input name='url' type='text' /> <input name='fullurl' type='hidden' />
    <select name="city"
    OnSubmit='converturl();location.href=fullurl.value.city;return false'>

    <option value="Dallas">Dallas
    <option value="Chicago">Chicago
    <option value="New York">New York
    </select><input type='submit' value=" Go " />
    </form>
    </code>
    <b>This script seems to work, but doesn't pass the city variable (url2) to bing.</b>
    <code>
    <script>
    function converturl() {
    document.go.url.value = document.go.url.value.replace(/\s/g, "");
    var url = document.getElementsByName("url")[0];
    var url2 = document.getElementsByName("url2")[0];
    var fullurl = document.getElementsByName("fullurl")[0];
    fullurl.value = "http://www.bing.com/search?&q=Resume+-jobs+-apply" + url.value

    }

    </script>


    <form name= "go" önsubmit='converturl();location.href=fullurl.value;return false'>
    <input name='url' type='text' /> <input name='fullurl' type='hidden' />
    <input type='submit' value=" Go " />
    </form>
    <select name="city"
    önSelect="location.href=url2.city.options[selectedIndex].value">
    <option selected>Please Select...
    <option value="Dallas">Dallas
    <option value="Chicago">Chicago
    <option value="New York">New York
    </select>
    </code>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    I think you are working way way way too hard.

    Code:
    <form action="http://www.bing.com/search" 
          onsubmit="this.q.value += (this.url.value + ' ' + this.city.value); return true;">
    <input type="hidden" name="q"
           value="Resume -jobs -apply -submit -required -wanted -template -wizard -free -write -sample " />
    <input name="url" type="text" /><!-- what is this for? -->
    <select name="city">
    <option selected value="">Please Select...
    <option value="Dallas">Dallas
    <option value="Chicago">Chicago
    <option value="New York">New York
    </select>
    <input type="submit" value=" Go " />
    </form>
    Not sure what the point of the url field is, but I plunked it in there just in case.

    NOTE: Bing will receive the city and url fields separately, in addition to seeing their values tacked onto the q= string, but that shouldn't hurt. If it does, there's a reasonably easy fix.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    mtriana (02-05-2010)

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thanks!!

    I appreciate your help. Yes, I'm working too hard...lol. Sorry for not replying sooner.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •