...

View Full Version : Passing javascript.write output in hidden text field



pagedrop
09-21-2011, 03:37 AM
Hello,

I use a iplocator api, which is javascript and gives out the city name, country and zipcode output

<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

Old Pedant
09-21-2011, 04:06 AM
<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.

pagedrop
09-21-2011, 04:26 AM
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

Old Pedant
09-21-2011, 05:44 AM
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: + '"/>'




<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...

Old Pedant
09-21-2011, 05:45 AM
By the by, language="javascript" is long obsolete. You really should be using type="text/javascript"

Either works, but you should get modernized.

pagedrop
09-21-2011, 05:50 AM
thank you

it works now, thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum