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 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Passing javascript.write output in hidden text field

    Hello,

    I use a iplocator api, which is javascript and gives out the city name, country and zipcode output
    PHP Code:
    <script language="JavaScript" src="http://www.somesite.com/somefile.js?key=apikey"></script>
    <script language="JavaScript">
    <!--
    document.write(ip2location_isp() + ', ' + ip2location_city() + ', ' + ip2location_zip_code() + ', ' + ip2location_net_speed());
    //-->
    </script> 
    my question or where i need help is that, i would like to output each of those as a hidden text field, so later i can store into mysq database with POST method from the hidden field.

    thank you in advance for your time n help

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,540
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Code:
    <script language="JavaScript" src="http://www.somesite.com/somefile.js?key=apikey"></script>
    <script language="JavaScript">
    document.write('<input name="isp" type="hidden" value="' + ip2location_isp() + /"/>' );
    document.write('<input name="city" type="hidden" value="' + ip2location_city() + '"/>' );
    document.write('<input name="zip" type="hidden" value="' + ip2location_zip_code() + '"/>' );
    document.write('<input name="speed" type="hidden" value="' + ip2location_net_speed() + '"/>' );
    </script>
    The need for <!-- and //--> disappeared when MSIE 3 went off the market...about 1999.
    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.

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    thank you

    but it seems not working, im not able to get the values showed up.
    Note: i changed the hidden to text to check, but not working.

    thank you once again

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,540
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Did the code you posted in your first post work?

    Whoops...I see one typo in there. I had + /"/>' after ip2location_isp() and it should of course be the same as the others: + '"/>'


    Code:
    <script language="JavaScript" src="http://www.somesite.com/somefile.js?key=apikey"></script>
    <script language="JavaScript">
    document.write('<input name="isp" type="hidden" value="' + ip2location_isp() + '"/>' );
    document.write('<input name="city" type="hidden" value="' + ip2location_city() + '"/>' );
    document.write('<input name="zip" type="hidden" value="' + ip2location_zip_code() + '"/>' );
    document.write('<input name="speed" type="hidden" value="' + ip2location_net_speed() + '"/>' );
    </script>
    Check carefully for any other typos. I don't see them, but...
    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:

    pagedrop (09-21-2011)

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,540
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    By the by, language="javascript" is long obsolete. You really should be using type="text/javascript"

    Either works, but you should get modernized.
    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.

  • #6
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Smile

    thank you

    it works now, thanks again


  •  

    Posting Permissions

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