php - jQuery updates hidden input value, but does not pass to POST variable -


i have built html form address data, , want compute latitude , longitude of address before commit form fields sql database via post variables.

right console shows edited hidden "latinput" , "lnginput" field dom lat/lng values. however, change not being captured post variables in php script.

hidden form fields:

<input type="hidden" name="latinput" id="latinput" value=""> <input type="hidden" name="lnginput" id="lnginput" value=""> 

jquery setting/checking dom updates hidden fields:

//insert new lat/lng variables hidden form inputs, php can access post , insert sql database $("#latinput").attr('value',locallat); $("#lnginput").attr('value',locallng);  //confirm hidden input fields set lat/lng values console.log("latinput set to: " + $("input[name=latinput]").val()); console.log("lnginput set to: " + $("input[name=lnginput]").val()); 

php script checking post variables lat/lng, , committing fields database:

$lat = $_post['latinput']; $lng = $_post['lnginput'];  echo('<p>post variable lat = '.$lat.'</p>'); echo('<p>post variable lng = '.$lng.'</p>');  //choose sql fields (column names), choose html form fields ("name" attribute) $sql = "insert $tablename (name,address1,city,state,zip,latitude,longitude) values ('$_post[firstname]','$_post[address1]','$_post[city]','$_post[state]','$_post[zipcode]','$_post[latinput]','$_post[lnginput]')"; 

please note--all other form fields (address1, city, etc.) passing post variables , entering database on submit. , though dom updating hidden latinput , lnginput fields, not pull through local $lat , $lng variables. post still returns no value. i've tried updating original hidden latinput , lnginput fields dummy data below, , dummy data passes through fine.

dummy data:

<input type="hidden" name="latinput" id="latinput" value="1.234"> <input type="hidden" name="lnginput" id="lnginput" value="2.345"> 

any ideas why dropping off?

thank help!

the proper way set input value using val() function.

$("#latinput").val(locallat); $("#lnginput").val(locallng); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -